Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save francois-blanchard/cb5b56d81773ff169a53 to your computer and use it in GitHub Desktop.

Select an option

Save francois-blanchard/cb5b56d81773ff169a53 to your computer and use it in GitHub Desktop.
Error Mysql when you try to delete row - Cannot delete or update a parent row: a foreign key constraint fails

Error Mysql when you try to delete row - Cannot delete or update a parent row: a foreign key constraint fails

You can't delete this row because any other is link to her with a foreign key

Find errors

  1. Try to delete
  2. View log with SHOW ENGINE INNODB STATUS;

Force delete row

  1. Disable foreign key SET FOREIGN_KEY_CHECKS=0;
  2. Delete row
  3. Enable foreign key SET FOREIGN_KEY_CHECKS=1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment