{"record":{"id":"b8275b547f33ce76","repo":"golang-migrate/migrate","slug":"no-database-name-b8275b","errorCode":null,"errorMessage":"no database name","messagePattern":"no database name","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"database/pgx/v5/pgx.go","lineNumber":40,"sourceCode":"\t\"github.com/jackc/pgx/v5/pgconn\"\n\t_ \"github.com/jackc/pgx/v5/stdlib\"\n)\n\nfunc init() {\n\tdb := Postgres{}\n\tdatabase.Register(\"pgx5\", &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)\n\ntype Config struct {\n\tMigrationsTable       string\n\tDatabaseName          string\n\tSchemaName            string\n\tmigrationsSchemaName  string\n\tmigrationsTableName   string\n\tStatementTimeout      time.Duration\n\tMigrationsTableQuoted bool\n\tMultiStatementEnabled bool\n\tMultiStatementMaxSize int\n}\n\ntype Postgres struct {\n\t// Locking and unlocking need to use the same connection\n\tconn     *sql.Conn","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/database/pgx/v5/pgx.go#L22-L58","documentation":"ErrNoDatabaseName is the sentinel error returned by the pgx v5 driver when Config.DatabaseName is empty in WithInstance, WithConnection, or Open. Several operations (e.g. ensuring the migrations table exists in the right database) require an explicit database name, and the driver refuses to guess. Callers can match it with errors.Is.","triggerScenarios":"Passing &pgxv5.Config{} (or a Config with DatabaseName: \"\") to WithInstance/WithConnection, or opening with a connection string lacking both a database path component and a DatabaseName — e.g. `postgres://host:5432` with no `/dbname`.","commonSituations":"Building Config programmatically from env vars where the DB name env var is unset; using DSNs built by string concatenation that drop the database segment; connecting to a specific connection endpoint (e.g. via a sidecar proxy) that omits the database in the URL.","solutions":["Set Config.DatabaseName explicitly, e.g. &pgxv5.Config{DatabaseName: \"myapp\"}.","Include the database in the DSN: postgres://user:pass@host:5432/myapp.","Validate required env vars (DB name) before constructing Config so empty strings fail early in your own code.","Use errors.Is(err, pgxv5.ErrNoDatabaseName) to branch and prompt for/derive the missing database name."],"exampleFix":"// before\ncfg := &pgxv5.Config{MigrationsTable: \"schema_migrations\"} // no DatabaseName\n// after\ncfg := &pgxv5.Config{MigrationsTable: \"schema_migrations\", DatabaseName: os.Getenv(\"DB_NAME\")}","handlingStrategy":"validation","validationCode":"if cfg.DatabaseName == \"\" {\n    return fmt.Errorf(\"DatabaseName is required for pgx migrations\")\n}","typeGuard":"func isConfigComplete(c *pgxv5.Config) bool { return c != nil && c.DatabaseName != \"\" }","tryCatchPattern":"drv, err := pgxv5.WithInstance(conn, cfg)\nif err != nil {\n    if errors.Is(err, pgxv5.ErrNoDatabaseName) {\n        return fmt.Errorf(\"set Config.DatabaseName or include /dbname in the DSN: %w\", err)\n    }\n    return err\n}","preventionTips":["Always include the database path segment in postgres:// DSNs","Fail fast on unset DB_NAME-style env vars before building Config","Add a startup validation step listing required Config fields"],"tags":["postgresql","config","missing-setting"],"backgroundTag":"missing-required-config-field","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}