// MySQL error reference

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
Error message
Check constraint '%s' is violated.

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 CHECK constraint to a table with existing rows that violate it.

How to fix it

  1. See the constraint's condition.

    SELECT constraint_name, check_clause FROM information_schema.check_constraints
    WHERE constraint_schema = DATABASE();
  2. 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

More keys and constraints errors

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.

// fewer errors, faster fixes

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.