文章内容

2020/7/24 11:04:19,作 者: 黄兵

Cannot add or update a child row: a foreign key constraint fails

今天在执行SQL语句的时候,出现如下错误:

[23000][1452] Cannot add or update a child row: a foreign key constraint fails (`A_Production`.`#sql-ef6_169`, CONSTRAINT `mata_keywords_description___fk_author` FOREIGN KEY (`author_id`) REFERENCES `author` (`id`)).

出现这个问题的原因具体没有查清楚,但是有这样说:

Foreign key relationships involve a parent table that holds the central data values, and a child table with identical values pointing back to its parent. The FOREIGN KEY clause is specified in the child table.


It will reject any INSERT or UPDATE operation that attempts to create a foreign key value in a child table if there is no a matching candidate key value in the parent table.

没有求证,无法确定,具体来源:ERROR 1452: Cannot add or update a child row: a foreign key constraint fails

解决方案:

删除auhtor_id,之后重新建一个author_id,设置未外键,问题解决。

新建和原来没有任何区别,但是这次没有报错,不清楚是什么问题。


参考资料:

1、ERROR 1452: Cannot add or update a child row: a foreign key constraint fails


黄兵个人博客原创。

转载请注明出处:黄兵个人博客 - Cannot add or update a child row: a foreign key constraint fails

分享到:

发表评论

评论列表