码迷,mamicode.com
首页 > 其他好文 > 详细

【转】 #1451 - Cannot delete or update a parent row: a foreign key constraint fails 问题的解决办法

时间:2014-06-26 21:31:40      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:class   blog   code   http   tar   ext   

转载地址:http://blog.csdn.net/donglynn/article/details/17056099

错误

SQL 查询:

DELETE FROM `zmax_lang` WHERE CONVERT( `zmax_lang`.`lang` USING utf8 ) = ‘fr‘ LIMIT 1

MySQL 返回:bubuko.com,布布扣

#1451 - Cannot delete or update a parent row: a foreign key constraint fails (`myreview/zmax_text`, CONSTRAINT `zmax_text_ibfk_1` FOREIGN KEY (`lang`) REFERENCES `zmax_lang` (`lang`)) 




以上是因为,改条记录的某个字段作为innodb的另外一个表的外链。而在删除操作时会自动检查外链。解决的办法之一是,不检查外链,只需将执行语句前加上下句即可:

SET FOREIGN_KEY_CHECKS = 0;

DELETE FROM `zmax_lang` WHERE CONVERT( `zmax_lang`.`lang` USING utf8 ) = ‘fr‘ LIMIT 1 

【转】 #1451 - Cannot delete or update a parent row: a foreign key constraint fails 问题的解决办法,布布扣,bubuko.com

【转】 #1451 - Cannot delete or update a parent row: a foreign key constraint fails 问题的解决办法

标签:class   blog   code   http   tar   ext   

原文地址:http://www.cnblogs.com/csshaw/p/3807962.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!