DBAtlas · Database operations atlas

3819: ER_CHECK_CONSTRAINT_VIOLATED: Check constraint is violated

MySQL

What does it mean?

The row you are inserting or updating violates a CHECK constraint defined on the table. In MySQL 8.0.16 and later, CHECK constraints are actually enforced (earlier versions ignored them).

Why does it happen?

The column value does not satisfy the condition in the CHECK expression (e.g. entering a negative price when CHECK (price >= 0) exists). After upgrading from older MySQL versions to 8.0.16+, it can appear unexpectedly because previously ignored constraints are now enforced.

How to fix it

Make sure the value satisfies the constraint condition; add validation on the application side. To see the constraint definition: SHOW CREATE TABLE my_table; If the constraint is truly unnecessary: ALTER TABLE my_table DROP CHECK constraint_name; or temporarily ALTER TABLE my_table ALTER CHECK constraint_name NOT ENFORCED; Also fix the source of the bad data.

Open in DBAtlas →

More from this engine