Help Center/ Relational Database Service/ Troubleshooting/ RDS for MySQL/ SQL Issues/ ERROR[1451] Reported When a Table with Foreign Keys Cannot Be Deleted
Updated on 2023-03-06 GMT+08:00

ERROR[1451] Reported When a Table with Foreign Keys Cannot Be Deleted

Scenario

The root user does not have the permissions required to delete or modify tables in the database. Error message is as follows:

ERROR[1451] -Cannot deleteorupdatea parent row:

aforeignkeyconstraintfails (…)

Fault Analysis

The FRM file also exists in sys_tables. This table has foreign key relationships with other tables and cannot be deleted directly.

A foreign key association has been configured in the RDS for MySQL DB instance. As a result, data cannot be updated or deleted. You can use the foreign_key_checks parameter to avoid this problem.

Solution

set session foreign_key_checks=off;
drop table table_name;

To delete the table, set foreign_key_checks to off.