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.

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

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

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.

Reference: Pinal Dave (https://blog.sqlauthority.com)

MySQL, SQL Error Messages
Previous Post
SQL SERVER – Synchronize Schema across Multiple Environment – How to Overcome Database Migration Challenge
Next Post
MySQL – Download MySQL Workbench Shortcut in PDF

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