golang-migrate/migrate · error
no config
Error message
no config
What it means
The CockroachDB driver defines ErrNilConfig ("no config") and returns it from WithInstance, WithConnection, and extractCustomQueryParams when the *Config pointer is nil. Without a config the driver cannot determine migrations table, lock table, or database name, so construction is refused.
Source
Thrown at database/cockroachdb/cockroachdb.go:31
"github.com/cockroachdb/cockroach-go/v2/crdb"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database"
"github.com/lib/pq"
)
func init() {
db := CockroachDb{}
database.Register("cockroach", &db)
database.Register("cockroachdb", &db)
database.Register("crdb-postgres", &db)
}
var DefaultMigrationsTable = "schema_migrations"
var DefaultLockTable = "schema_lock"
var (
ErrNilConfig = fmt.Errorf("no config")
ErrNoDatabaseName = fmt.Errorf("no database name")
)
type Config struct {
MigrationsTable string
LockTable string
ForceLock bool
DatabaseName string
}
type CockroachDb struct {
db *sql.DB
isLocked atomic.Bool
// Open and WithInstance need to guarantee that config is never nil
config *Config
}
View on GitHub (pinned to 01a9643f14)
Solutions
- Build the driver via cockroachdb.WithURL("cockroachdb://user:pass@host:26257/db?sslmode=disable") so a populated Config is created.
- Or pass a populated &cockroachdb.Config{MigrationsTable: ..., DatabaseName: ...} to WithInstance/WithConnection.
- Guard the call site: if cfg == nil { return nil, errors.New("cockroachdb config required") } before invoking the library.
Example fix
// before
d, err := cockroachdb.WithInstance(db, nil)
// after
d, err := cockroachdb.WithURL("cockroachdb://root@localhost:26257/migrations?sslmode=disable") Defensive patterns
Strategy: validation
Validate before calling
if cfg == nil {
return fmt.Errorf("cockroachdb config must not be nil")
}
if cfg.DatabaseName == "" {
return fmt.Errorf("cockroachdb config requires a database name")
} Type guard
func validCockroachConfig(cfg *cockroachdb.Config) bool {
return cfg != nil && cfg.DatabaseName != ""
} Try / catch
d, err := cockroachdb.WithInstance(db, cfg)
if err != nil {
if errors.Is(err, cockroachdb.ErrNilConfig) {
return fmt.Errorf("use cockroachdb.WithURL or pass a populated *cockroachdb.Config")
}
return err
} Prevention
- Use cockroachdb.WithURL to derive the Config from a DSN instead of constructing drivers by hand.
- Never pass nil for *Config; centralize driver creation in one factory function.
- Test the driver-construction helper for nil-input behavior.
When it happens
Trigger: Calling cockroachdb.WithInstance(conn, nil), cockroachdb.WithConnection(conn, nil), or extractCustomQueryParams with a nil config.
Common situations: Skipping cockroachdb.WithURL / Open and wiring the driver by hand; a nil config returned from an earlier failed parse; uninitialized struct pointer in a DI container.
Related errors
AI-assisted analysis of golang-migrate/migrate@01a9643f14 (2026-09-02).
Data as JSON: /api/errors/febf56fd4095bb48.
Report an issue: GitHub.