MySQL error 3819: Check constraint is violated
A row breaks a CHECK constraint on the table. MySQL enforces CHECK constraints from version 8.0.16; older versions parsed and ignored them.
- Error number
3819- Name
ER_CHECK_CONSTRAINT_VIOLATED- SQLSTATE
HY000- Category
- Keys and constraints
What it means
The row's values made a CHECK condition false, so the insert or update was rejected. The message names the constraint. Before 8.0.16 MySQL accepted CHECK clauses but didn't enforce them, so data loaded on an old server can break constraints after an upgrade or when the constraint is added.
Common causes
- Application data that the constraint was written to keep out, such as a negative price.
- Adding a
CHECKconstraint to a table with existing rows that violate it.
How to fix it
-
See the constraint's condition.
SELECT constraint_name, check_clause FROM information_schema.check_constraints WHERE constraint_schema = DATABASE();
-
Fix the data, then retry; or find rows that would fail before adding the constraint.
SELECT * FROM products WHERE NOT (price >= 0);
Reproduce it safely
CREATE TEMPORARY TABLE t (price DECIMAL(10,2), CONSTRAINT chk_price CHECK (price >= 0)); INSERT INTO t VALUES (-1); -- ERROR 3819 (HY000): Check constraint 'chk_price' is violated.
Related errors
1048Column cannot be null23514PostgreSQL: check constraint violation547SQL Server: Statement conflicted with a constraintSQLITE_CONSTRAINT_CHECKSQLite: CHECK constraint failed
More keys and constraints errors
1062Duplicate entry for key1061Duplicate key name1452Foreign key fails: cannot add child row1451Foreign key fails: cannot delete parent row1216Cannot add or update a child row1217Cannot delete or update a parent row1215Cannot add foreign key constraint3780Foreign key columns are incompatible
The code and message text are from the MySQL 8.4 Error Message Reference. Browse the full MySQL error list or search every database error.
Work on MySQL in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for MySQL and the other databases you use.