我有一个名为 Book_details 的表,它的主键为 Bid 现在这个 BID 也是同一数据库中其他两个表的外键(即slend_details, Book_inventory)
当我将数据插入 inventory_details 表时,出现以下错误:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__book_invent__Bid__1367E606". The conflict occurred in database "library_management", table "dbo.Book_details", column 'Bid'.
The statement has been terminated.
这是我使用的插入语句:
insert into Book_inventory (Bid, present) values (001,1)
这是我用于我的 book_inventory 表的创建语句:
create table book_inventory (
Bid varchar(50) Not null Foreign Key references Book_details(Bid),
present bit Not null*
)
我什至检查了值,即我尝试输入 book_inventory 表的数据存在于 Book_details 表中。我仍然得到错误。有人可以帮帮我吗?
最佳答案
您的插入;
insert into Book_inventory (Bid,present) values (001,1)
将 Bid
作为整数插入,这很可能意味着它将值简化为 1
,它不作为 Bid
存在。
引用该值并将其作为实际字符串插入应该可行;
insert into Book_inventory (Bid,present) values ('001',1)
关于mysql - 插入数据时,插入语句与外键约束冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20780604/