{"record":{"id":"47e7b88ad4e4c8da","repo":"golang-migrate/migrate","slug":"no-database-name-47e7b8","errorCode":null,"errorMessage":"no database name","messagePattern":"no database name","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"database/yugabytedb/yugabytedb.go","lineNumber":32,"sourceCode":"\t\"github.com/cenkalti/backoff/v4\"\n\t\"github.com/golang-migrate/migrate/v4\"\n\t\"github.com/golang-migrate/migrate/v4/database\"\n\t\"github.com/jackc/pgconn\"\n\t\"github.com/jackc/pgerrcode\"\n\t\"github.com/lib/pq\"\n)\n\nconst (\n\tDefaultMaxRetryInterval    = time.Second * 15\n\tDefaultMaxRetryElapsedTime = time.Second * 30\n\tDefaultMaxRetries          = 10\n\tDefaultMigrationsTable     = \"migrations\"\n\tDefaultLockTable           = \"migrations_locks\"\n)\n\nvar (\n\tErrNilConfig          = errors.New(\"no config\")\n\tErrNoDatabaseName     = errors.New(\"no database name\")\n\tErrMaxRetriesExceeded = errors.New(\"max retries exceeded\")\n)\n\nfunc init() {\n\tdb := YugabyteDB{}\n\tdatabase.Register(\"yugabyte\", &db)\n\tdatabase.Register(\"yugabytedb\", &db)\n\tdatabase.Register(\"ysql\", &db)\n}\n\ntype Config struct {\n\tMigrationsTable     string\n\tLockTable           string\n\tForceLock           bool\n\tDatabaseName        string\n\tMaxRetryInterval    time.Duration\n\tMaxRetryElapsedTime time.Duration\n\tMaxRetries          int","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/database/yugabytedb/yugabytedb.go#L14-L50","documentation":"The yugabytedb driver returns ErrNoDatabaseName ('no database name') when the provided config has an empty DatabaseName. The driver needs to know which YSQL database to connect to in order to create/check the migrations table. It is a public sentinel comparable with errors.Is.","triggerScenarios":"Calling WithInstance/WithConnection/Open with a Config whose DatabaseName is \"\"; Open with a URL that lacks a database name component; WithInstance after detecting len(config.DatabaseName) == 0.","commonSituations":"Forgetting to set DatabaseName when constructing Config manually; parsing a connection URL that omits the database path; env-var-driven config where the DB_NAME variable is unset or empty after trimming.","solutions":["Set cfg.DatabaseName (or include the database in the Open URL, e.g. yugabytedb://host/dbname) before creating the driver.","Validate the config before the call: if cfg.DatabaseName == \"\" return a clear error early.","Check env/flag plumbing that supplies the database name (env var may be unset).","Compare errors.Is(err, yugabytedb.ErrNoDatabaseName) to pinpoint the missing field.","If passing to WithInstance after parsing a URL, use the same name used to open the sql.DB connection."],"exampleFix":"// before\ncfg := &yugabytedb.Config{}\nm, err := yugabytedb.WithInstance(session, cfg)\n// after\ncfg := &yugabytedb.Config{DatabaseName: os.Getenv(\"YUGABYTE_DB\")}\nif cfg.DatabaseName == \"\" {\n\treturn nil, errors.New(\"YUGABYTE_DB must be set\")\n}\nm, err := yugabytedb.WithInstance(session, cfg)","handlingStrategy":"validation","validationCode":"if cfg == nil || cfg.DatabaseName == \"\" {\n\treturn nil, errors.New(\"yugabytedb: database name is required\")\n}\ndriver, err := yugabytedb.WithInstance(session, cfg)","typeGuard":"func hasDatabaseName(cfg *yugabytedb.Config) bool {\n\treturn cfg != nil && len(cfg.DatabaseName) > 0\n}","tryCatchPattern":null,"preventionTips":["Load DatabaseName from env/config at startup and fail fast if empty","Include the database in the Open URL instead of relying on separate config","Validate all required Config fields (DatabaseName, MigrationsTable) in one place before driver creation"],"tags":["go","golang-migrate","yugabytedb","missing-config-field"],"backgroundTag":"missing-database-name","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}