当我们只是需要删除数据库中的一个table的时候,往往会因为tables之间的依赖关系,而导致删除失败,那到底要怎么删除有依赖关系的table呢?
这类的删除出错,我是这样解决的:
错误操作:mysql> delete from instances where id = 7;
错误提示: ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`nova`.`security_group_instance_association`, CONSTRAINT `security_group_instance_association_ibfk_2` FOREIGN KEY (`instance_id`) REFERENCES `instances` (`id`))
解决方案:
mysql> delete from security_group_instance_association where id=7;
Query OK, 1 row affected (0.06 sec)
mysql> delete from instance_info_caches where id=7;
Query OK, 1 row affected (0.06 sec)
mysql> delete from instances where id = 7;
Query OK, 1 row affected (0.05 sec)