1741
MySQLERRORNotableForeign KeysHIGH confidence
No such key value in referenced table
Production Risk
Medium — data integrity violation blocked.
What this means
A row being inserted or updated references a key value that does not exist in the parent table, violating the foreign key constraint.
Why it happens
- 1The referenced parent row does not exist.
- 2The parent row was deleted before the child insert/update was committed.
How to reproduce
trigger — this will error
trigger — this will error
INSERT INTO orders (customer_id) VALUES (9999); -- customer 9999 does not exist
expected output
ERROR 1741 (HY000): No key value found in referenced table 'customers'.
Fix
Insert the parent row first
Insert the parent row first
INSERT INTO customers (id) VALUES (9999); INSERT INTO orders (customer_id) VALUES (9999);
Why this works
Ensures the referenced key exists before inserting the child row.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 1741 ER_NO_SUCH_KEY_VALUE
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev