Cannot delete or update a parent row: a foreign key constraint fails

If you have encountered this error, this is maybe because:

  1. There is a table within another schema (“database” in mysql terminology) which has a FK reference
  2. The innodb internal data dictionary is out of sync with the mysql one.

To apply your queries, simply bypass foreign keys security check.
This is the solution:

SET FOREIGN_KEY_CHECKS=0;
YOUR_QUERY here

After your queries have been done, reset to default foreign keys security check:

SET FOREIGN_KEY_CHECKS=1;

You’re done.

Advertisements
Cannot delete or update a parent row: a foreign key constraint fails

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s