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
- List constraints:
\d tablenamein psql, or querypg_constraint. - Use the exact constraint name (mind quoting/case).
- Use
DROP CONSTRAINT IF EXISTSto make the drop idempotent.
Related & next steps
Reference: PostgreSQL 18 — ALTER TABLE.
Thanks — noted. This helps keep the database accurate.