{"record":{"id":"abc06797170f3719","repo":"golang-migrate/migrate","slug":"no-schema-abc067","errorCode":null,"errorMessage":"no schema","messagePattern":"no schema","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"database/pgx/v5/pgx.go","lineNumber":41,"sourceCode":"\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\n\tdb       *sql.DB","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/database/pgx/v5/pgx.go#L23-L59","documentation":"ErrNoSchema is the sentinel error returned by the pgx (and pgx v5) drivers when a schema name is required but empty. In pgx, Open/WithInstance derive the schema from Config.SchemaName or the `search_path`/x-no-lock-etc DSN settings; if no schema can be determined, the driver returns ErrNoSchema because migrations must be scoped to a known schema.","triggerScenarios":"Calling pgx.Open/WithInstance with a Config whose SchemaName is empty and a DSN that does not carry a schema (no search_path in the options and no x-schema-name-style parameter), e.g. `postgres://user:pass@host/db` with &Config{}.","commonSituations":"Deployments where the app connects with search_path set server-side per role but the migrate DSN is built independently and loses it; forgetting to set SchemaName when the database user's default schema (public) was intentionally renamed; multi-tenant setups where the schema comes from the request context and is sometimes empty.","solutions":["Set Config.SchemaName explicitly (e.g. \"public\") or include search_path in the DSN: postgres://.../db?search_path=myschema.","If relying on search_path, add it to the connection string's options parameter so Open can derive the schema.","Validate that the schema value is non-empty before constructing Config in multi-tenant code paths.","Match with errors.Is(err, pgx.ErrNoSchema) and surface a clear message about which schema setting is missing."],"exampleFix":"// before\ndsn := \"postgres://user:pass@host/db\"\ndrv, err := pgx.Open(dsn) // ErrNoSchema if search_path absent\n// after\ndsn := \"postgres://user:pass@host/db?search_path=myschema\"","handlingStrategy":"validation","validationCode":"if cfg.SchemaName == \"\" && !strings.Contains(dsn, \"search_path\") {\n    cfg.SchemaName = \"public\"\n}","typeGuard":"func hasSchema(c *pgx.Config) bool { return c != nil && c.SchemaName != \"\" }","tryCatchPattern":"drv, err := pgx.Open(dsn)\nif err != nil {\n    if errors.Is(err, pgx.ErrNoSchema) {\n        return fmt.Errorf(\"set SchemaName or add ?search_path=<schema> to the DSN: %w\", err)\n    }\n    return err\n}","preventionTips":["Set SchemaName explicitly in multi-tenant environments rather than relying on server defaults","Include search_path in the migrate DSN, not just the application connection","Validate schema presence per tenant before running migrations"],"tags":["postgresql","schema","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"}