golang-migrate/migrate · error

no config

Error message

no config

What it means

ErrNilConfig is a sentinel error in the sqlite3 migrate driver meaning the *Config pointer passed to WithInstance or WithConnection was nil. The driver needs the config (e.g. MigrationsTable) to operate, so it refuses to construct a migration driver without one.

Source

Thrown at database/sqlite3/sqlite3.go:25

	"io"
	nurl "net/url"
	"strconv"
	"strings"
	"sync/atomic"

	"github.com/golang-migrate/migrate/v4"
	"github.com/golang-migrate/migrate/v4/database"
	_ "github.com/mattn/go-sqlite3"
)

func init() {
	database.Register("sqlite3", &Sqlite{})
}

var DefaultMigrationsTable = "schema_migrations"
var (
	ErrDatabaseDirty  = fmt.Errorf("database is dirty")
	ErrNilConfig      = fmt.Errorf("no config")
	ErrNoDatabaseName = fmt.Errorf("no database name")
)

type Config struct {
	MigrationsTable string
	DatabaseName    string
	NoTxWrap        bool
}

type Sqlite struct {
	db       *sql.DB
	isLocked atomic.Bool

	config *Config
}

func WithInstance(instance *sql.DB, config *Config) (database.Driver, error) {
	if config == nil {

View on GitHub (pinned to 01a9643f14)

Solutions

  1. Pass a non-nil &sqlite3.Config{} (optionally setting MigrationsTable)
  2. Use migrate.Open / database.Open with the sqlite3:// URL so the driver builds the config for you
  3. Check the caller that constructs the Config for a code path returning nil

Example fix

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

Strategy: validation

Validate before calling

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

Type guard

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

Prevention

When it happens

Trigger: Calling database/sqlite3.WithInstance(db, nil) or WithConnection(conn, nil), or Open-ing a sqlite3 URL when the driver internally builds a nil Config.

Common situations: Constructing the driver programmatically without building a Config struct; wiring migrate.NewWithInstance with a hand-rolled source; refactors that accidentally drop the config argument.

Related errors


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