将行添加到外键后我无法删除行 [英] I can't delete row after append it a foreign key
本文介绍了将行添加到外键后我无法删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个表second
和third
second_id(PRIMARY KEY) second_name
1 .........
2 .......
3 .........
third_id(PRIMARY KEY) third_name second_id(FOREIGN KEY for second.second_id)
1 ..... 1
2 ..... 1
3 ..... 1
4 ..... 2
5 ..... 2
现在我想从second
其中second_id=2
( DELETE FROM second WHERE second_id=2
)删除一行,但是它不起作用.它说 Successful 0 row(s) affected
,而且是在我向third.second_id
附加外键之后发生的(在创建表后添加了外键).
Now i want to delete a row fromsecond
where second_id=2
(DELETE FROM second WHERE second_id=2
) but it does not work. It says Successful 0 row(s) affected
What is more is, it happened after i append a foreign key to third.second_id
(i added foreign key after table is created).
推荐答案
您将必须删除third
表中具有second_id = 2的行,然后从second
中删除id = 2或具有
You will have to delete the rows in third
table with second_id = 2 and then delete the rows from second
with id = 2 or have ON DELETE CASCADE
in the foreign key constraint
这篇关于将行添加到外键后我无法删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文