Fix for MySQL error Code 1217 – A foreign key constraint fails


Posted by Andrew McCombe on Wed Aug 13, 2014

If you’re trying to update or drop a table in MySQL and you’re getting the error ‘Error Code: 1217. Cannot delete or update a parent row: a foreign key constraint fails’ you need to toggle the foreign_key_checks variable first.

The reason for this error is because your tables have foreign keys which rely on the table you’re attempting to change. Here’s the fix for MySQL error Code 1217 – A foreign key constraint fails:

I hope this helps someone else.