MySQL error 1217: Cannot delete or update a parent row
The older form of the foreign key failure on delete or update of a referenced row. Current servers usually report 1451 instead.
- Error number
1217- Name
ER_ROW_IS_REFERENCED- SQLSTATE
23000- Category
- Keys and constraints
What it means
1217 has the same meaning as 1451: child rows still reference the row you are deleting or changing, and the foreign key doesn't cascade. The message omits the constraint details. DROP TABLE on a parent table can also raise it.
Common causes
- Deleting a referenced row, or dropping a table that other tables reference.
How to fix it
-
Follow the steps for error 1451, and drop child tables (or their foreign keys) before the parent table.
-
Find the tables that reference the parent.
SELECT table_name, constraint_name FROM information_schema.referential_constraints WHERE constraint_schema = DATABASE() AND referenced_table_name = 'customers';
Related errors
More keys and constraints errors
1062Duplicate entry for key1061Duplicate key name1452Foreign key fails: cannot add child row1215Cannot add foreign key constraint3780Foreign key columns are incompatible1822Missing index for foreign key constraint1824Failed to open the referenced table1048Column cannot be null
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.
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.