Error code
MySQL 1217
MYSQL1217
Database Error Code· An error code returned by a database server such as PostgreSQL or MySQL.
What it means
Cannot delete a parent row — foreign key constraint prevents DELETE.
How to fix it
- Delete or update the child rows first before removing the parent.
- Change the foreign key definition to ON DELETE CASCADE if automatic child removal is acceptable.
- Use a transaction to delete both parent and children together.
Not affiliated with MySQL. Answer summarized from the manufacturer's manual linked above; consult that source for the authoritative procedure.
More MySQL codes
- 1213Deadlock found when trying to get lock — two transactions blocked each other
- 1216Cannot add a child row — foreign key constraint fails on INSERT
- 1040Too many connections — the server has reached its connection limit
- 1044Access denied for user to database — missing GRANT
- 1045Access denied for user — wrong credentials
- 1048Column cannot be null — a required column received a NULL
- 1050Table already exists — CREATE TABLE failed because the name is taken
- 1051Unknown table — a DROP or query referenced a table that does not exist
- 1054Unknown column — the column name is not defined on the table
- 1062Duplicate entry for key — unique constraint violated
- 1064SQL syntax error — the query contains invalid SQL
- 1136Column count does not match value count — INSERT column and value lists differ