What it means
A CHECK constraint is a rule on the table, such as “quantity must be positive” or “status must be one of these values”. Your insert or update produced a row for which the rule is false, so Postgres rejected the whole statement. The DETAIL line (Failing row contains (...)) shows the full row as Postgres saw it, after defaults and triggers ran. Through the Supabase API it arrives as HTTP 400 with code: "23514".
Step 1: read the rule that failed
The constraint name is in the message. Print its definition:
select conname, pg_get_constraintdef(oid)
from pg_constraint
where conrelid = 'public.orders'::regclass
and contype = 'c';Compare it with the Failing row contains values. The mismatch is usually obvious once both are side by side.
The usual causes
- Case or spelling. The rule allows
'pending', the app sends'Pending'or'in_progress'when the rule says'in-progress'. - A new value in the app, old rule in the database. The UI added a status, the migration that widens the rule was never run on this project.
- Empty string instead of null. A form sends
''and the rule ischar_length(name) > 0. Note the reverse: a CHECK passes when the expression is null, sonullslips through unless the column is alsonot null. - Numbers out of range, such as a discount of 120 when the rule is
between 0 and 100, or a negative quantity from a “minus” button. - A trigger or default changed the row before the check ran. That is why the failing row can contain values you never sent.
Fix the data or widen the rule
If the app is wrong, normalise the value before saving (for example lower-case it). If the rule is out of date, replace it. Adding it as not valid first avoids a long table scan under a heavy lock, then validate checks the existing rows separately:
alter table public.orders drop constraint orders_status_check;
alter table public.orders
add constraint orders_status_check
check (status in ('pending', 'paid', 'shipped', 'cancelled')) not valid;
alter table public.orders validate constraint orders_status_check;If validate fails with check constraint "orders_status_check" of relation "orders" is violated by some row, find the offenders, fix them, and validate again:
select id, status
from public.orders
where not (status in ('pending', 'paid', 'shipped', 'cancelled'));Handle it in the app
A check violation is a user-facing validation error, not a crash. Map it to a message:
const { error } = await supabase.from('orders').insert(order);
if (error?.code === '23514') {
showError('Some values are not allowed. Please check the form.');
}Better still, validate the same rule in the form so users rarely reach the database error. Keep the CHECK anyway: it is the rule that holds when a script, an admin or a bug bypasses the form.
How to verify
Repeat the exact insert that failed: it should succeed. Then try a value the rule should reject and confirm you still get 23514. A constraint that accepts everything is not protecting anything.
Related guides
- Supabase “duplicate key value violates unique constraint” on upsert – the five causes
- “relation does not exist” in Postgres and Supabase – schema, quotes, search_path, cache
- Supabase rpc “Could not find the function … in the schema cache” and “function does not exist”
- SECURITY DEFINER functions without a fixed search_path – the risk and the fix
More in Postgres errors and performance · all guides