{"record":{"id":"15303bd2a43c992d","repo":"golang-migrate/migrate","slug":"no-database-name-15303b","errorCode":null,"errorMessage":"no database name","messagePattern":"no database name","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"database/postgres/postgres.go","lineNumber":39,"sourceCode":"\t\"github.com/lib/pq\"\n)\n\nfunc init() {\n\tdb := Postgres{}\n\tdatabase.Register(\"postgres\", &db)\n\tdatabase.Register(\"postgresql\", &db)\n}\n\nvar (\n\tmultiStmtDelimiter = []byte(\";\")\n\n\tDefaultMigrationsTable       = \"schema_migrations\"\n\tDefaultMultiStatementMaxSize = 10 * 1 << 20 // 10 MB\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\tMigrationsTableQuoted bool\n\tMultiStatementEnabled bool\n\tDatabaseName          string\n\tSchemaName            string\n\tmigrationsSchemaName  string\n\tmigrationsTableName   string\n\tStatementTimeout      time.Duration\n\tMultiStatementMaxSize int\n}\n\ntype Postgres struct {\n\t// Locking and unlocking need to use the same connection","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/database/postgres/postgres.go#L21-L57","documentation":"ErrNoDatabaseName indicates a Config (or parsed URL) without a database name, which golang-migrate needs to track migrations per database. WithInstance, Open, and WithConnection return it before touching the database. It is exported so callers can match it with errors.Is.","triggerScenarios":"postgres.WithInstance with Config{DatabaseName: \"\"}; cockroachdb.Open with a URL whose path is empty (e.g. postgres://host:26257?sslmode=disable); building Config dynamically where the database name resolved to an empty string.","commonSituations":"URL missing the /dbname path segment; environment variable for DB name unset and interpolated as empty; hardcoding a config struct and forgetting DatabaseName; moving from lib/pq to cockroachdb driver which enforces the same check.","solutions":["Set Config.DatabaseName explicitly when using WithInstance/WithConnection","Include a database name in the URL path: postgres://user:pass@host:5432/mydb?sslmode=disable","Fail fast with errors.Is(err, postgres.ErrNoDatabaseName) to give a clear message at startup"],"exampleFix":"// before\nurl := \"postgres://user:pass@localhost:5432?sslmode=disable\"\n// after\nurl := \"postgres://user:pass@localhost:5432/mydb?sslmode=disable\"","handlingStrategy":"validation","validationCode":"if cfg != nil && cfg.DatabaseName == \"\" {\n    return errors.New(\"Config.DatabaseName must be set\")\n}\nif u, _ := url.Parse(dsn); strings.Trim(u.Path, \"/\") == \"\" {\n    return errors.New(\"DSN must include a database name path\")\n}","typeGuard":null,"tryCatchPattern":"if err := openMigrate(); err != nil {\n    if errors.Is(err, postgres.ErrNoDatabaseName) {\n        log.Fatal(\"database name missing: set it in the URL path or Config.DatabaseName\")\n    }\n    panic(err)\n}","preventionTips":["Always include /dbname in the Postgres URL path","Fail at config-load time when the DB name env var is empty","Set Config.DatabaseName explicitly for WithInstance/WithConnection usage"],"tags":["configuration","missing-value","postgres","sentinel-error"],"backgroundTag":"missing-database-name","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}