# Postgres error 23514: new row for relation "x" violates check constraint "y"

> A row failed a CHECK constraint.

Source: https://scribase.com/postgres-errors/23514

SQLSTATE class: Integrity Constraint Violation. Over PostgREST/supabase-js this maps to HTTP 400.

## Causes

- The value breaks a rule the table enforces, such as a negative price or a status outside the allowed list.
- Adding a CHECK constraint to a table whose existing rows break it.

## Fixes

- Read the constraint (\d+ table, or pg_get_constraintdef) and validate the same rule in the app.
- When adding a constraint to a large table, add it NOT VALID, fix old rows, then VALIDATE CONSTRAINT.

## Example

```sql
alter table products add constraint price_positive check (price_cents > 0) not valid;
update products set price_cents = 1 where price_cents <= 0;
alter table products validate constraint price_positive;
```