golang-migrate/migrate · error

no config

Error message

no config

What it means

ErrNilConfig is the sqlserver driver's sentinel error returned when a nil *Config is passed to WithInstance or WithConnection. Without a config the driver cannot determine the migrations table or schema.

Source

Thrown at database/sqlserver/sqlserver.go:28

	"strconv"
	"strings"
	"sync/atomic"

	"github.com/Azure/go-autorest/autorest/adal"
	"github.com/golang-migrate/migrate/v4"
	"github.com/golang-migrate/migrate/v4/database"
	mssql "github.com/microsoft/go-mssqldb" // mssql support
)

func init() {
	database.Register("sqlserver", &SQLServer{})
}

// DefaultMigrationsTable is the name of the migrations table in the database
var DefaultMigrationsTable = "schema_migrations"

var (
	ErrNilConfig                 = fmt.Errorf("no config")
	ErrNoDatabaseName            = fmt.Errorf("no database name")
	ErrNoSchema                  = fmt.Errorf("no schema")
	ErrDatabaseDirty             = fmt.Errorf("database is dirty")
	ErrMultipleAuthOptionsPassed = fmt.Errorf("both password and useMsi=true were passed")
)

var lockErrorMap = map[int]string{
	-1:   "The lock request timed out.",
	-2:   "The lock request was canceled.",
	-3:   "The lock request was chosen as a deadlock victim.",
	-999: "Parameter validation or other call error.",
}

// Config for database
type Config struct {
	MigrationsTable string
	DatabaseName    string
	SchemaName      string

View on GitHub (pinned to 01a9643f14)

Solutions

  1. Pass &sqlserver.Config{} with the fields you need set (MigrationsTable, DatabaseName, SchemaName)
  2. Prefer opening via URL (e.g. sqlserver://user:pass@host:port?database=...) so the driver builds the config
  3. Audit the call site for a nil-returning config constructor

Example fix

// before
drv, err := sqlserver.WithInstance(db, nil)
// after
cfg := &sqlserver.Config{MigrationsTable: "schema_migrations"}
drv, err := sqlserver.WithInstance(db, cfg)
Defensive patterns

Strategy: validation

Validate before calling

if cfg == nil {
    return errors.New("sqlserver driver requires a non-nil Config")
}
drv, err := sqlserver.WithInstance(db, cfg)

Type guard

func configProvided(cfg *sqlserver.Config) bool { return cfg != nil }

Prevention

When it happens

Trigger: Calling sqlserver.WithInstance(db, nil) or WithConnection(conn, nil); code paths constructing the driver manually with a missing config.

Common situations: Programmatic driver setup in tests or embedded migrations; refactors dropping the config argument; copying an example that passes a zero value where a pointer was required.

Related errors


AI-assisted analysis of golang-migrate/migrate@01a9643f14 (2026-09-02). Data as JSON: /api/errors/661262e896bb81dd. Report an issue: GitHub.