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" (SQLSTATE 42704): 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 statement referenced a constraint that does not exist on the given relation. PostgreSQL raises SQLSTATE 42704 (undefined_object).

  • The named constraint is not defined on that table.
  • Common in ALTER TABLE … DROP 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 that isn’t present on that table (typo, already dropped, or wrong table) cannot be resolved, so PostgreSQL reports 42704.

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 in psql, or query pg_constraint.
  2. Use the exact constraint name (mind quoting/case).
  3. Use DROP CONSTRAINT IF EXISTS to make the drop idempotent.

Related & next steps

Reference: PostgreSQL 18 — ALTER TABLE.

Was this helpful?