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
- List constraints:
\d tablenameor querypg_constraint. - Use the exact constraint name and correct relation.
- Use
DROP CONSTRAINT IF EXISTSfor idempotency.
Related & next steps
Reference: PostgreSQL 18 — ALTER TABLE.
Thanks — noted. This helps keep the database accurate.