欢迎投稿

今日深度:

Cannot delete or update a parent row: a foreign key constrai

Cannot delete or update a parent row: a foreign key constraint fails解决方法,constraintfails


我在使用delete from table语句清空一个表数据时,报错 Cannot delete or update a parent row: a foreign key constraint fails。

先把我的数据库贴出来。

tb_device表





tb_device_status_now表



正题:


最开始我直接清空tb_device,报错。看数据库发现tb_device_status_now中的字段与其外键关联所以不能清空。所以改为先清空tb_device_status_now表,再清空tb_device。结果发现还是报错!再看数据库,发现tb_device表中dev_master字段与dev_id字段也是外键关联。。。。

所以要先清空dev_master字段,才能清空tb_device整张表。

清空某字段数据的sql语句:update table set column=null


最后我的删除顺序:




www.htsjk.Com true http://www.htsjk.com/shujukunews/7178.html NewsArticle Cannot delete or update a parent row: a foreign key constraint fails解决方法,constraintfails 我在使用delete from table语句清空一个表数据时,报错Cannot delete or update a parent row: a foreign key constraint fails。 先...
评论暂时关闭