解决“Cannot add or update a child row”报错
2017-06-29 00:00
106 查看
今天在给一张表添加外键时出现如下报错:
Cannot add or update a child row: a foreign key constraint fails (`test`.`#sql-206b_231`, CONSTRAINT `FK_responsemessage` FOREIGN KEY (`userid`) REFERENCES `requestmessage` (`userid`))
后来找到了原因,记录一下。
执行如下语句:
有结果就表示不正常。
正常情况下,关联表(responsemessage)的字段“userid”应该是被关联表(requestmessage)的字段“userid”的子集,否则就会出现报错。
解决方法就是删掉有问题的行,或者修改。
Cannot add or update a child row: a foreign key constraint fails (`test`.`#sql-206b_231`, CONSTRAINT `FK_responsemessage` FOREIGN KEY (`userid`) REFERENCES `requestmessage` (`userid`))
后来找到了原因,记录一下。
执行如下语句:
SELECT `userid` FROM `responsemessage` WHERE `userid` NOT IN (SELECT `userid` FROM `requestmessage`)
有结果就表示不正常。
正常情况下,关联表(responsemessage)的字段“userid”应该是被关联表(requestmessage)的字段“userid”的子集,否则就会出现报错。
解决方法就是删掉有问题的行,或者修改。
相关文章推荐
- Cannot add or update a child row: a foreign key constraint fails 解决办法
- MySQL ERROR 1452 - Cannot add or update a child row: a foreign key
- ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint......
- cannot add or update a child row: a foreign key constraint fails
- Error 'Cannot add or update a child row: a foreign key constraint fails
- Cannot add or update a child row: a foreign key constraint fails 问题的处理
- MySQL外键 Cannot add or update a child row
- 刷新数据库总是报错:不能增加或者更新约束, Cannot add or update a child row: a foreign key constraint fails
- Mysql error 1452 - Cannot add or update a child row: a foreign key constraint fails
- IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constrai nt fails (`mxonline
- [转][Err] 1452 - Cannot add or update a child row: a foreign key constraint fail
- MySQL外键 Cannot add or update a child row错误的实例解释
- mysql添加外键失败:sql 1452 Cannot add or update a child row:a foreign key constraint fails
- django admin报错IntegrityError:'Cannot add or update a child row: a foreign key constraint fails'
- [Mysql] 添加外键失败:Cannot add or update a child row:a foreign key constraint fails
- mysql Cannot add or update a child row: a foreign key constraint fails
- mysql cannot add or update a child row
- ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint......
- MySQL外键 Cannot add or update a child row错误的实例解释
- 解决1452- Cannot add or update a child rowa foreign key constraint fails问题