未捕获的错误:调用成员函数execute()

时间:2018-08-27 11:30:40

标签: mysql sql

我在将外键添加到vessel_id时遇到问题。错误和代码如下:

错误:

ERROR 1452: Cannot add or update a child row: a foreign key constraint fails ( qubqmlcs_db .#sql-5ec_1c , CONSTRAINT FK_boatlogs_vessels_id FOREIGN KEY ( vessel_id ) REFERENCES船只( vessel_id ) ON DELETE NO ACTION ON UPDATE NO ACTION)

SQL语句:

ALTER TABLE `qubqmlcs_db`.`boatlogs` ADD INDEX `FK_boatlogs_vessels_id_idx` (`vessel_id` ASC); ; ALTER TABLE `qubqmlcs_db`.`boatlogs` ADD CONSTRAINT `FK_boatlogs_vessels_id` FOREIGN KEY (`vessel_id`) REFERENCES `qubqmlcs_db`.`vessels` (`vessel_id`) ON DELETE NO ACTION ON UPDATE NO ACTIONACTION;

这是我要添加FK键的表:

enter image description here

这是引用的表:

enter image description here

以下是索引:

enter image description here

这是外键:

enter image description here

为什么会出现此错误?我只是不明白。我试图删除vessel_id并再次创建它,然后添加FK密钥,但是每次都会出现此错误。非常感谢您的帮助!

0 个答案:

没有答案