MYSQL – Could not Drop Object [Content] (‘Cannot delete or update a parent row: a foreign key constraint fails’, 1217) DROP DATABASE DatabaseName

If you are using MySQL following, you must have faced following error when you want to drop a table or database. This error happens when we try to drop a table or database which has a foreign key constraint associated with another table, schema or database. MySQL reports it as error 1217, saying a foreign key constraint fails.

Could not Drop Object [Content] (‘Cannot delete or update a parent row: a foreign key constraint fails’, 1217) DROP DATABASE DatabaseName

Could not drop object dialog.

Here is a simple workaround to this problem. Disable the keys right before you drop a table or a database. Remember to practice this on the database which you are confident to drop it.

SET FOREIGN_KEY_CHECKS=0;
DROP DATABASE humanresources;
DROP TABLE MyTable;
SET FOREIGN_KEY_CHECKS=1;

Let me know if you are using any method for this purpose.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.

MySQL, SQL Error Messages
Previous Post
Idempotent Deployment Scripts: Safe to Run Twice
Next Post
SSMS Keyboard Shortcuts Worth Learning

Related Posts

1 Comment. Leave new

  • Jerry L. Cutshaw
    February 3, 2014 8:44 pm

    Hello Pinal. I’m a veteran SQL Server DBA that wants to branch out into MySQL. Any suggestions where I might find some tutorials geared toward SQL Server vets?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.