-1

在另外两张表上,我已经将 foreign 设置为 d_desavanja->id 字段,但在这张表上,我不能。

我怎样才能让它工作?

SQL query:

ALTER TABLE  `d_des_kat` ADD FOREIGN KEY (  `desavanje_id` ) REFERENCES  `desavanja`.`d_desavanja` (

`id`
) ON DELETE CASCADE ON UPDATE CASCADE ;

MySQL said: 

#1452 - Cannot add or update a child row: a foreign key constraint fails (`desavanja/#sql-12f3_5af2e`, CONSTRAINT `#sql-12f3_5af2e_ibfk_1` FOREIGN KEY (`desavanje_id`) REFERENCES `d_desavanja` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) 
4

1 回答 1

2

您有一行d_des_kat违反了约束。检查您的数据以确保所有非 NULLd_des_kat.desavanje_id值与现有idd_desavanja.

以下查询应向您显示有问题的行:

SELECT *
FROM d_des_kat
WHERE desavanje_id NOT IN (SELECT id FROM d_desavanja)
于 2012-10-11T15:06:11.117 回答