MySQL错误1452(23000)无法添加或更新外键约束失败的子行

时间:2014-12-04 07:16:04

标签: mysql

这是我为表格输入的内容

mysql> create table A6M351kjp.Claim (ClaimID INT (10) NOT NULL, VIN INT (10) NOT NULL, ClaimDate DateTime Null, ClaimStatus VarChar(45) Null, Primary Key (ClaimID));

在这里添加了外键

mysql> alter table A6M351kjp.Claim add foreign key (VIN) references Car(VIN);

输入数据

mysql> insert into A6M351kjp.Claim (ClaimID, VIN, ClaimDate, ClaimStatus) values (101, 901, '2014-01-01', 'Open');
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`A6M351kjp`.`Claim`, CONSTRAINT `Claim_ibfk_1` FOREIGN KEY (`VIN`) REFERENCES `Car` (`VIN`))

导致此错误的原因是什么?如何解决?

由于

1 个答案:

答案 0 :(得分:0)

Car表中不存在

901。因为它被引用为外键,所以需要在父表中。