2

This is weird and I haven't ever encountered this.

I'm simply dropping a whole database.

$ mysql -u $RDS_USER -p$RDS_PASS -h $RDS_HOST -e "DROP DATABASE dev_test"

And yet it fails with this...

ERROR 1217 (23000) at line 1: Cannot delete or update a parent row: a foreign key constraint fails

I then go to the database itself and I see that most of the tables have been dropped except for two.

Why does this happen?

I'm using MySQL 5.6.

1
  • I just got the same problem. Only 2 tables remaining in the database. Not FK to tables on other DBs. No FK between the tables. I can't see what's bothering MySQL... Commented Jan 31 at 9:30

2 Answers 2

1

Try the DROP DATABASE a second time. Since most tables are gone, that may have relieved enough constraints to allow the last two tables to go.

Or... Do those two tables have FKs to each other? In this case, neither can be dropped "first". Hence, Greenforest35's answer (turn off FKs) seems to be the only solution.

Consider filing a bug report with http://bugs.mysql.com saying explaining that DROP DATABASE should be smarter -- such as ignoring the FKs automatically. (Or at least the ones that will be removed later by later tables -- this would take some analysis.)

Worse yet... Are there constraints between your remaining tables and table(s) in other database(s)?

(So many reasons not to bother with FKs.)

0

you should just drop all the foreign key constraints

alter table test drop foreign key testconstraint
1
  • 3
    I want to drop the ENTIRE database. Do I have to drop everything inside first? Commented Jan 12, 2018 at 5:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.