PostgreSQL: new row violates check constraint
ERROR: new row for relation "<t>" violates check constraint "<constraint>"A value failed a CHECK constraint on the table. The row broke a rule the schema enforces, such as a range or an allowed set of values. Correct the value, or review and adjust the constraint if it is wrong.
What this error means
A CHECK constraint is a boolean rule every row must satisfy, like price >= 0 or status IN (...). When a write produces a row that fails the rule, Postgres rejects it, names the constraint, and prints the failing row in the DETAIL.
It often signals that application validation has drifted from the database rule.
How to fix it
The value breaks the rule
Correct the value so it satisfies the constraint's condition.
You are not sure what the rule requires
Inspect the constraint definition.
\d+ ordersThe constraint itself is outdated
If the rule is wrong, drop and recreate it with the correct condition.
ALTER TABLE orders DROP CONSTRAINT orders_status_check;
ALTER TABLE orders
ADD CONSTRAINT orders_status_check
CHECK (status IN ('pending', 'paid', 'shipped'));How to avoid it next time
- Keep application validation and database constraints in sync so they agree on what is valid.
- Name constraints clearly, so the error tells you which rule failed.
Frequently asked questions
How do I see what the check requires?
Run \d+ tablename in psql; it prints each CHECK constraint's expression.
Should I validate in the app or the database?
Both. The database constraint is the guarantee; app validation gives users a friendlier message before the write.
Stop struggling with SQL
Use FluentDB, the AI database client for macOS.
Related errors
Part of the PostgreSQL error reference. Last reviewed 2026-07-31.