drizzle-team/drizzle-orm · error · Error
You can't specify 'public' as schema name. Postgres is using
Error message
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
What it means
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.
Source
Thrown at drizzle-orm/src/pg-core/schema.ts:66
return pgSequenceWithSchema(name, options, this.schemaName);
});
getSQL(): SQL {
return new SQL([sql.identifier(this.schemaName)]);
}
shouldOmitSQLParens(): boolean {
return true;
}
}
export function isPgSchema(obj: unknown): obj is PgSchema {
return is(obj, PgSchema);
}
export function pgSchema<T extends string>(name: T) {
if (name === 'public') {
throw new Error(
`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`,
);
}
return new PgSchema(name);
}
View on GitHub (pinned to b7862528fd)
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.
Example fix
// before
const publicSchema = pgSchema('public'); // error
export const users = publicSchema.table('users', { id: serial().primaryKey() });
// after
export const users = pgTable('users', { id: serial().primaryKey() }); Defensive patterns
Strategy: type-guard
Validate before calling
function pgSchemaSafe<T extends string>(name: T) {
if (name === 'public') {
throw new Error(`Use pgTable() for the default 'public' schema instead of pgSchema('public')`);
}
return pgSchema(name);
}
// generate schemas only for non-public names
schemas.filter((s) => s !== 'public').forEach((s) => pgSchemaSafe(s)); Type guard
function isNonPublicSchema(name: string): boolean {
return name !== 'public';
} Prevention
- Use pgTable() for tables in the default public schema.
- Filter 'public' out when generating schemas programmatically.
- Reserve pgSchema() for custom namespaces.
When it happens
Trigger: 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.
Common situations: 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().
Related errors
- You have an empty array for "${name}" enum values
- Insert select error: selected fields are not the same or are
- You have an empty array for "${name}" enum values
- unsupported relation type
- Invalid relation "${relation.fieldName}" for table "${it.sch
AI-assisted analysis of drizzle-team/drizzle-orm@b7862528fd (2026-08-03).
Data as JSON: /data/errors/315ff40dd947f2e5.json.
Report an issue: GitHub.