{"record":{"id":"a11fe8cde01d2484","repo":"golang-migrate/migrate","slug":"no-config-a11fe8","errorCode":null,"errorMessage":"no config","messagePattern":"no config","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"database/mysql/mysql.go","lineNumber":34,"sourceCode":"\t\"strings\"\n\t\"sync/atomic\"\n\t\"time\"\n\n\t\"github.com/go-sql-driver/mysql\"\n\t\"github.com/golang-migrate/migrate/v4/database\"\n)\n\nvar _ database.Driver = (*Mysql)(nil) // explicit compile time type check\n\nfunc init() {\n\tdatabase.Register(\"mysql\", &Mysql{})\n}\n\nvar DefaultMigrationsTable = \"schema_migrations\"\n\nvar (\n\tErrDatabaseDirty    = fmt.Errorf(\"database is dirty\")\n\tErrNilConfig        = fmt.Errorf(\"no config\")\n\tErrNoDatabaseName   = fmt.Errorf(\"no database name\")\n\tErrAppendPEM        = fmt.Errorf(\"failed to append PEM\")\n\tErrTLSCertKeyConfig = fmt.Errorf(\"to use TLS client authentication, both x-tls-cert and x-tls-key must not be empty\")\n)\n\ntype Config struct {\n\tMigrationsTable  string\n\tDatabaseName     string\n\tNoLock           bool\n\tStatementTimeout time.Duration\n}\n\ntype Mysql struct {\n\t// mysql RELEASE_LOCK must be called from the same conn, so\n\t// just do everything over a single conn anyway.\n\tconn     *sql.Conn\n\tdb       *sql.DB\n\tisLocked atomic.Bool","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/database/mysql/mysql.go#L16-L52","documentation":"ErrNilConfig in database/mysql is returned by WithInstance, WithConnection and extractCustomQueryParams when the *Config argument is nil. The MySQL driver needs Config for DatabaseName and MigrationsTable, so a nil config makes migration state tracking impossible. It is a caller-side configuration bug.","triggerScenarios":"mysql.WithInstance(db, nil); mysql.WithConnection(ctx, db, nil); a nil config flowing into extractCustomQueryParams through Open.","commonSituations":"Declaring `var cfg *mysql.Config` without assigning, wrappers that pass through nil, refactors replacing WithConfig with manual struct construction.","solutions":["Pass a non-nil *mysql.Config to WithInstance/WithConnection","Use mysql.WithConfig/WithInstance with a proper DSN so config is built for you","Add a nil-check in your driver bootstrap before constructing migrate"],"exampleFix":"// before\nvar cfg *mysql.Config\nd, err := mysql.WithInstance(sqlDB, cfg)\n// after\ncfg := &mysql.Config{DatabaseName: \"app\", MigrationsTable: \"schema_migrations\"}\nd, err := mysql.WithInstance(sqlDB, cfg)","handlingStrategy":"validation","validationCode":"if cfg == nil {\n    return fmt.Errorf(\"mysql migration requires non-nil *mysql.Config\")\n}","typeGuard":"func hasMysqlConfig(cfg *mysql.Config) bool { return cfg != nil }","tryCatchPattern":"if err != nil {\n    if errors.Is(err, mysql.ErrNilConfig) {\n        return fmt.Errorf(\"nil mysql config passed to driver construction\")\n    }\n    return err\n}","preventionTips":["Build config via a single constructor/WithConfig call site","Nil-check at the driver factory boundary","Add tests covering WithInstance/WithConnection config paths"],"tags":["go","golang-migrate","mysql","config","nil-pointer"],"backgroundTag":"nil-config-passed-to-driver","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}