Help Center/ Relational Database Service/ Troubleshooting/ RDS for MySQL/ SQL Issues/ Failed to Delete a Table with a Foreign Key
Updated on 2023-03-06 GMT+08:00

Failed to Delete a Table with a Foreign Key

Scenario

When an RDS for MySQL table with a foreign key is deleted, the following error message will be displayed, which is irrelevant to user permissions:

ERROR 1451 (23000): Cannot delete or update parent row: a foreign key constraint fails ………… 

Possible Causes

There is a foreign key relationship between this table and another table. A link is established between the data in the two tables. To prevent foreign key constraints from being violated, data in the tables cannot be updated or deleted.

You can set FOREIGN_KEY_CHECKS to off to remove the foreign key relationship. For details, see FOREIGN KEY Constraints.

Solution

Set FOREIGN_KEY_CHECKS to off.

set session foreign_key_checks=off; 
drop table table_name;