// MySQL error reference

MySQL error 1216: Cannot add or update a child row

The older form of the foreign key failure on insert or update, without the constraint details. Current servers report 1452 instead.

Error number
1216
Name
ER_NO_REFERENCED_ROW
SQLSTATE
23000
Category
Keys and constraints
Error message
Cannot add or update a child row: a foreign key constraint fails

What it means

1216 has the same meaning as 1452: the row you are writing references a parent row that doesn't exist. The difference is only that the message doesn't include the constraint definition. You may still see it from older servers or some code paths.

Common causes

  • Inserting or updating a child row whose parent doesn't exist.

How to fix it

  1. Follow the steps for error 1452: insert the parent first, or fix the foreign key value.

  2. Use SHOW ENGINE INNODB STATUS to see the latest foreign key error in detail.

    SHOW ENGINE INNODB STATUS;

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.