# 42P15 — Invalid schema definition

> Source-backed reference for PostgreSQL SQLSTATE 42P15.
---

# 42P15 — Invalid schema definition

## At a glance {#at-a-glance}

`42P15` (**invalid_schema_definition**) CREATE SCHEMA can be rejected when its schema declarations disagree.

<!-- BEGIN SQLSTATE FACTS: generated by scripts/generate.py; do not edit -->

| Field | Value |
| --- | --- |
| SQLSTATE | `42P15` |
| Condition | `invalid_schema_definition` |
| Status | `active` |
| Known present by | `7.4` |
| Locked snapshots | `9.0.23, 9.1.24, 9.2.24, 9.3.25, 9.4.26, 9.5.25, 9.6.24, 10.23, 11.22, 12.22, 13.23, 14.24, 15.19, 16.15, 17.11, 18.6, 19beta3` |
| Macros | `ERRCODE_INVALID_SCHEMA_DEFINITION` |
| Aliases | `—` |

<!-- source facts: data/errcodes/42P15.json -->
<!-- END SQLSTATE FACTS -->

## Meaning {#meaning}

Schema-definition validation applies while transforming the objects contained by `CREATE SCHEMA`. The `setSchemaName` helper rejects a contained object's explicitly specified schema when it differs from the one `CREATE SCHEMA` is currently creating. This is a contained-object declaration mismatch, not two independent top-level schemas or a missing-schema lookup.

## Diagnosis {#diagnosis}

Read both schema identifiers from the message and the complete `CREATE SCHEMA` statement. Find which contained `CREATE TABLE`, sequence, view, or other object supplied the conflicting qualification. Check generated DDL and `search_path` separately; changing `search_path` cannot reconcile two names that the statement explicitly supplies.

## Response {#response}

Generate `CREATE SCHEMA` with one intended name and keep each contained object's explicit qualification under that name, or omit the qualification where the command supplies the context. Correct the migration generator or quoting. A failed `CREATE SCHEMA` does not by itself prove that a partial schema was committed; inspect the catalog only when cleanup or a prior transaction requires it. If this ERROR occurs inside an explicit transaction, `ROLLBACK` or `ROLLBACK TO` a pre-error savepoint before retrying.

## Messages {#messages}

Representative source messages include: message: `CREATE specifies a schema (%s) different from the one being created (%s)`. Placeholders are filled by the actual object, column, or parameter.

## Versions {#versions}

The locked catalogue shows this condition by PostgreSQL 7.4; behavior here is fixed to PostgreSQL 18.6 source. Catalogue presence is a range boundary, not proof that every message or feature began in that release.

## Related {#related}

- [`3F000`](../3f000/)
- [`42P06`](../42p06/)

## Sources {#sources}

Source messages, line anchors, and evidence limits are recorded in [authored evidence](../data/evidence/42p15.json).

- `src/backend/parser/parse_utilcmd.c:4229-4233` ([fixed source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_utilcmd.c#L4229-L4233))
