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

undefined_object constraint “…” of relation “…” does not exist — 42704

PostgreSQL error “constraint … of relation … does not exist — 42704” (SQLSTATE 42704): what it means, common causes, and how to fix it.

PG 9.6, 10, 11, 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed Jun 2026 Grounded in source

Diagnostic Queries

Symptoms

A statement referenced a constraint that does not exist on the given relation. PostgreSQL raises SQLSTATE 42704 (undefined_object). This is the errors-new counterpart of the message-keyed constraint page.

  • The named constraint is not defined on that table.
  • Common in ALTER TABLE … DROP CONSTRAINT/VALIDATE CONSTRAINT.
  • Constraint names are case-sensitive when quoted.

What the server log shows

ERROR:  constraint "orders_amount_check" of relation "orders" does not exist

Why PostgreSQL raises this — what the manual says

the ALTER TABLE reference (DROP CONSTRAINT):

“This form drops the specified constraint on a table, along with any index underlying the constraint.”

Constraints are named objects attached to a relation. Referencing a name not present on that table (typo, already dropped, or wrong table) cannot be resolved, so PostgreSQL reports 42704. See the companion message page for the same wording.

Common causes

  • A typo or wrong case in the constraint name.
  • The constraint was already dropped or never existed.
  • Referencing the wrong relation.

How to fix it

  1. List constraints: \d tablename or query pg_constraint.
  2. Use the exact constraint name and correct relation.
  3. Use DROP CONSTRAINT IF EXISTS for idempotency.

Related & next steps

Reference: PostgreSQL 18 — ALTER TABLE.

Was this helpful?