SQLSTATE 42P06 ERROR Class 42: Syntax Error or Access Rule Violation

duplicate_schema schema “…” already exists — 42P06

PostgreSQL error "schema "…" already exists" (SQLSTATE 42P06): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Diagnostic Queries

Symptoms

A CREATE SCHEMA tried to create a schema whose name already exists in the database. PostgreSQL raises SQLSTATE 42P06 (duplicate_schema).

  • A schema with that name already exists.
  • Schema names are unique within a database.
  • Common in re-run migrations.

What the server log shows

ERROR:  schema "reporting" already exists

Why PostgreSQL raises this — what the manual says

As the CREATE SCHEMA reference (Description) explains:

A schema with that name already exists in the current database; schema names must be unique per database — choose a different name or add IF NOT EXISTS to skip creation when it already exists.

Schema names are unique within a database. Creating one that already exists collides with the existing schema, so PostgreSQL reports 42P06.

Common causes

  • Re-running a migration that creates the schema.
  • The schema was created earlier.
  • A name clash with an existing schema.

How to fix it

  1. Use CREATE SCHEMA IF NOT EXISTS for idempotency.
  2. Check existence via \dn or pg_namespace.
  3. Choose a unique schema name.

Related & next steps

Reference: PostgreSQL 18 — CREATE SCHEMA.

Was this helpful?