{"id":"315ff40dd947f2e5","repo":"drizzle-team/drizzle-orm","slug":"you-can-t-specify-public-as-schema-name-postgre-315ff4","errorCode":null,"errorMessage":"You can't specify 'public' as schema name. Postgres is using public schema by default. If you want to use 'public' schema, just use pgTable() instead of creating a schema","messagePattern":"You can't specify 'public' as schema name\\. Postgres is using public schema by default\\. If you want to use 'public' schema, just use pgTable\\(\\) instead of creating a schema","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/pg-core/schema.ts","lineNumber":66,"sourceCode":"\t\treturn pgSequenceWithSchema(name, options, this.schemaName);\n\t});\n\n\tgetSQL(): SQL {\n\t\treturn new SQL([sql.identifier(this.schemaName)]);\n\t}\n\n\tshouldOmitSQLParens(): boolean {\n\t\treturn true;\n\t}\n}\n\nexport function isPgSchema(obj: unknown): obj is PgSchema {\n\treturn is(obj, PgSchema);\n}\n\nexport function pgSchema<T extends string>(name: T) {\n\tif (name === 'public') {\n\t\tthrow new Error(\n\t\t\t`You can't specify 'public' as schema name. Postgres is using public schema by default. If you want to use 'public' schema, just use pgTable() instead of creating a schema`,\n\t\t);\n\t}\n\n\treturn new PgSchema(name);\n}\n","sourceCodeStart":48,"sourceCodeEnd":73,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/pg-core/schema.ts#L48-L73","documentation":"pgSchema (schema.ts:64) explicitly rejects the name 'public'. Postgres uses the public schema by default and Drizzle's pgTable() already targets it, so declaring pgSchema('public') would be redundant and would double-qualify identifiers. The fix is to skip schema creation and use pgTable() directly.","triggerScenarios":"Calling pgSchema('public') and then using its .table() helper; auto-generating schema declarations from a list that includes 'public'; migrating a multi-schema setup that naively includes the default schema.","commonSituations":"Reflecting a database into Drizzle definitions and including 'public'; copy-pasting a schema block and forgetting to rename; tooling that wraps every schema name in pgSchema().","solutions":["Do not create a schema for 'public'; define those tables with pgTable() (no schema).","When programmatically generating schemas, skip or filter out the name 'public'.","Reserve pgSchema() for non-default namespaces only."],"exampleFix":"// before\nconst publicSchema = pgSchema('public'); // error\nexport const users = publicSchema.table('users', { id: serial().primaryKey() });\n\n// after\nexport const users = pgTable('users', { id: serial().primaryKey() });","handlingStrategy":"type-guard","validationCode":"function pgSchemaSafe<T extends string>(name: T) {\n  if (name === 'public') {\n    throw new Error(`Use pgTable() for the default 'public' schema instead of pgSchema('public')`);\n  }\n  return pgSchema(name);\n}\n// generate schemas only for non-public names\nschemas.filter((s) => s !== 'public').forEach((s) => pgSchemaSafe(s));","typeGuard":"function isNonPublicSchema(name: string): boolean {\n  return name !== 'public';\n}","tryCatchPattern":null,"preventionTips":["Use pgTable() for tables in the default public schema.","Filter 'public' out when generating schemas programmatically.","Reserve pgSchema() for custom namespaces."],"tags":["schema","public","validation","definition"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}