{"record":{"id":"96e4d967492e027f","repo":"golang-migrate/migrate","slug":"no-database-name-96e4d9","errorCode":null,"errorMessage":"no database name","messagePattern":"no database name","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"database/pgx/pgx.go","lineNumber":49,"sourceCode":"\nfunc init() {\n\tdb := Postgres{}\n\tdatabase.Register(\"pgx\", &db)\n\tdatabase.Register(\"pgx4\", &db)\n}\n\nvar (\n\tmultiStmtDelimiter = []byte(\";\")\n\n\tDefaultMigrationsTable       = \"schema_migrations\"\n\tDefaultMultiStatementMaxSize = 10 * 1 << 20 // 10 MB\n\tDefaultLockTable             = \"schema_lock\"\n\tDefaultLockStrategy          = LockStrategyAdvisory\n)\n\nvar (\n\tErrNilConfig      = fmt.Errorf(\"no config\")\n\tErrNoDatabaseName = fmt.Errorf(\"no database name\")\n\tErrNoSchema       = fmt.Errorf(\"no schema\")\n\tErrDatabaseDirty  = fmt.Errorf(\"database is dirty\")\n)\n\ntype Config struct {\n\tMigrationsTable       string\n\tDatabaseName          string\n\tSchemaName            string\n\tLockTable             string\n\tLockStrategy          string\n\tmigrationsSchemaName  string\n\tmigrationsTableName   string\n\tStatementTimeout      time.Duration\n\tMigrationsTableQuoted bool\n\tMultiStatementEnabled bool\n\tMultiStatementMaxSize int\n}\n","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/database/pgx/pgx.go#L31-L67","documentation":"ErrNoDatabaseName means the driver could not determine which PostgreSQL database migrations apply to. pgx's ErrNoDatabaseName is raised by WithInstance/WithConnection/Open when config.DatabaseName is empty and the connected session reports an empty CURRENT_DATABASE(); the identical message also exists in cockroachdb, where Open returns it when the database name parsed from the URL is empty (database/cockroachdb/cockroachdb.go:67).","triggerScenarios":"Calling cockroachdb Open with a URL missing the database path (e.g. cockroachdb://user@host:26257/); or pgx WithInstance with an empty config.DatabaseName while the connection has no current database set.","commonSituations":"DSN templates that drop the trailing /dbname; connecting through a proxy/URL rewrite that strips the path; forgetting that the database must exist and be named in the URL rather than only in query params.","solutions":["Include the database name in the connection URL path: cockroachdb://user:pass@host:26257/mydb","Or set config.DatabaseName explicitly when using WithInstance","Verify with SELECT CURRENT_DATABASE() that your connection actually has a current database"],"exampleFix":"// before\nurl := \"cockroachdb://root@localhost:26257/?sslmode=disable\"\n// after\nurl := \"cockroachdb://root@localhost:26257/defaultdb?sslmode=disable\"","handlingStrategy":"validation","validationCode":"u, _ := url.Parse(dsn)\nif strings.Trim(u.Path, \"/\") == \"\" {\n    return errors.New(\"connection URL must include the database name in the path\")\n}\nif cfg != nil && cfg.DatabaseName == \"\" {\n    cfg.DatabaseName = strings.Trim(u.Path, \"/\")\n}","typeGuard":null,"tryCatchPattern":"drv, err := pgx.WithInstance(db, cfg)\nif errors.Is(err, pgx.ErrNoDatabaseName) {\n    return fmt.Errorf(\"no database name: set cfg.DatabaseName or use a URL path like postgres://host/db: %w\", err)\n}","preventionTips":["Always include /dbname in the connection URL path","Set config.DatabaseName explicitly in containerized/templated environments","Run SELECT CURRENT_DATABASE() in a smoke test to confirm session state"],"tags":["postgres","cockroachdb","configuration","database-name","url-parameters"],"backgroundTag":"missing-database-name","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}