简体   繁体   English

无法使用外键更新/删除/截断表

[英]Unable to update/delete/truncate table with foreign key

I have 2 tables 我有2张桌子

CREATE TABLE table1 (
    id1 int(10) NOT NULL PRIMARY KEY,
    name varchar(20)
);    

CREATE TABLE table2 (
    newid int(10) NOT NULL PRIMARY KEY,
    f_id int(10)
);

Now, I have added a foreign key constrain 现在,我添加了一个外键约束

ALTER TABLE table2 
ADD CONSTRAINT fk_id FOREIGN KEY (f_id) REFERENCES table1 (id)
ON DELETE CASCADE ON UPDATE CASCADE;

Now, the problem is I am unable to update/delete/truncate the table 'table2'. 现在,问题是我无法更新/删除/截断表“ table2”。 What is the exact problem here and how to solve it? 这里的确切问题是什么以及如何解决?

外键强制执行参照完整性,请尝试从表1和表2中删除记录。您无法截断具有FK的表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM