MySQL 8.4Lab-verified · 2026-11-29

MySQL ERROR 3819 (HY000): Check constraint is violated

A row did not satisfy a CHECK constraint, on INSERT, UPDATE or when adding the constraint.

MySQL 8.4.13
3819 (HY000): Check constraint 'order_items_chk_1' is violated.

Jump to a cause

  1. 01INSERT a value the CHECK does not allow
  2. 02UPDATE one column of a rule that compares two columns
  3. 03ADD CONSTRAINT CHECK on a table that already has bad rows

Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-11-29 · container image mysql:8.4

Since MySQL 8.0.16, CHECK constraints are enforced. A row that makes the condition false is rejected with ERROR 3819, and the message names the constraint, for example order_items_chk_1.

To see what the constraint actually checks, look it up in information_schema.CHECK_CONSTRAINTS. Below are three cases reproduced on MySQL 8.4. MySQL has no Korean or Japanese translation for this message, so it appears in English.

01INSERT a value the CHECK does not allow

The table was created with qty INT CHECK (qty > 0). INSERT INTO order_items VALUES (1, 0) fails with Check constraint 'order_items_chk_1' is violated. An unnamed constraint gets an automatic name <table>_chk_<n>.

information_schema.CHECK_CONSTRAINTS showed order_items_chk_1 = (qty > 0). Inserting qty 1 worked.

Setup
Setuprun as lab_a
CREATE TABLE order_items (id INT PRIMARY KEY, qty INT CHECK (qty > 0));
OUTPUT
Query OK, 0 rows affected (0.02 sec)
Reproducerun as lab_a
INSERT INTO order_items VALUES (1, 0);
✕ ERROR
ERROR 3819 (HY000): Check constraint 'order_items_chk_1' is violated.
Checkrun as lab_a
SELECT CONSTRAINT_NAME, CHECK_CLAUSE FROM information_schema.CHECK_CONSTRAINTS WHERE CONSTRAINT_SCHEMA = DATABASE();
OUTPUT
+-------------------+--------------+
| CONSTRAINT_NAME   | CHECK_CLAUSE |
+-------------------+--------------+
| order_items_chk_1 | (`qty` > 0)  |
+-------------------+--------------+
1 row in set (0.00 sec)

Name your constraints (CONSTRAINT name CHECK …) so the error message tells you which rule failed.

After the fixrun as lab_a
INSERT INTO order_items VALUES (1, 1);
SELECT * FROM order_items;
✓ SUCCESS
Query OK, 1 row affected (0.01 sec)

+----+------+
| id | qty  |
+----+------+
|  1 |    1 |
+----+------+
1 row in set (0.00 sec)

02UPDATE one column of a rule that compares two columns

Coupons have CONSTRAINT coupons_period_chk CHECK (end_date >= start_date). Moving only start_date to 2024-06-01 while end_date is still 2024-05-31 fails with ERROR 3819.

The constraint is checked on the final row of the statement, so change both dates in one UPDATE: SET start_date = '2024-06-01', end_date = '2024-06-30' succeeded.

Setup
Setuprun as lab_a
CREATE TABLE coupons (id INT PRIMARY KEY, start_date DATE, end_date DATE,
  CONSTRAINT coupons_period_chk CHECK (end_date >= start_date));
INSERT INTO coupons VALUES (1, '2024-05-01', '2024-05-31');
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 1 row affected (0.01 sec)
Reproducerun as lab_a
UPDATE coupons SET start_date = '2024-06-01' WHERE id = 1;
✕ ERROR
ERROR 3819 (HY000): Check constraint 'coupons_period_chk' is violated.
Checkrun as lab_a
SELECT CONSTRAINT_NAME, CHECK_CLAUSE FROM information_schema.CHECK_CONSTRAINTS WHERE CONSTRAINT_NAME = 'coupons_period_chk';
OUTPUT
+--------------------+------------------------------+
| CONSTRAINT_NAME    | CHECK_CLAUSE                 |
+--------------------+------------------------------+
| coupons_period_chk | (`end_date` >= `start_date`) |
+--------------------+------------------------------+
1 row in set (0.00 sec)
After the fixrun as lab_a
UPDATE coupons SET start_date = '2024-06-01', end_date = '2024-06-30' WHERE id = 1;
SELECT * FROM coupons;
✓ SUCCESS
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

+----+------------+------------+
| id | start_date | end_date   |
+----+------------+------------+
|  1 | 2024-06-01 | 2024-06-30 |
+----+------------+------------+
1 row in set (0.00 sec)

03ADD CONSTRAINT CHECK on a table that already has bad rows

ALTER TABLE products ADD CONSTRAINT products_price_chk CHECK (price >= 0) fails with ERROR 3819, because MySQL checks existing rows when adding the constraint and row 2 has price -500.

Find the rows with the negated condition, WHERE NOT (price >= 0), fix them (here UPDATE … SET price = 500 WHERE id = 2), then the same ALTER TABLE succeeded on all 3 rows.

Setup
Setuprun as lab_a
CREATE TABLE products (id INT PRIMARY KEY, price INT);
INSERT INTO products VALUES (1, 1000), (2, -500), (3, 2000);
OUTPUT
Query OK, 0 rows affected (0.02 sec)

Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
ALTER TABLE products ADD CONSTRAINT products_price_chk CHECK (price >= 0);
✕ ERROR
ERROR 3819 (HY000): Check constraint 'products_price_chk' is violated.
Checkrun as lab_a
SELECT id, price FROM products WHERE NOT (price >= 0);
OUTPUT
+----+-------+
| id | price |
+----+-------+
|  2 |  -500 |
+----+-------+
1 row in set (0.00 sec)
Fixrun as lab_a
UPDATE products SET price = 500 WHERE id = 2;
OUTPUT
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
After the fixrun as lab_a
ALTER TABLE products ADD CONSTRAINT products_price_chk CHECK (price >= 0);
SELECT * FROM products;
✓ SUCCESS
Query OK, 3 rows affected (0.04 sec)
Records: 3  Duplicates: 0  Warnings: 0

+----+-------+
| id | price |
+----+-------+
|  1 |  1000 |
|  2 |   500 |
|  3 |  2000 |
+----+-------+
3 rows in set (0.00 sec)

FAQ

How do I see what a check constraint checks in MySQL?

SELECT CONSTRAINT_NAME, CHECK_CLAUSE FROM information_schema.CHECK_CONSTRAINTS WHERE CONSTRAINT_SCHEMA = DATABASE(); shows each constraint and its condition.

Where does a name like order_items_chk_1 come from?

It is the automatic name MySQL gives a CHECK constraint written without CONSTRAINT name: table name, _chk_, and a number.

Why does ALTER TABLE ADD CONSTRAINT CHECK fail with 3819?

Existing rows break the condition. Find them with WHERE NOT (<condition>), fix or delete them, and run the ALTER TABLE again.

How do I update two columns that must stay in order, like start and end dates?

Change both in a single UPDATE. The CHECK is evaluated on the result of the statement, so the intermediate state is never checked.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13