// MySQL error reference

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
Error message
Cannot delete or update a parent row: a foreign key constraint fails

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

  1. Follow the steps for error 1451, and drop child tables (or their foreign keys) before the parent table.

  2. 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

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.