[英]insert statement conflicted with the foreign key constraint? Why is this an issue in my case?
I know this gets asked a lot, but in my case, I feel like it shouldn't be an issue. 我知道这个问题经常被问到,但就我而言,我觉得这不应该成为问题。 My table has 2 foreign keys that allow for nulls, so I should be able to leave them blank, right?
我的表有2个允许为null的外键,所以我应该可以将它们留空,对吗?
My insert statement: 我的插入语句:
INSERT INTO Child (ChildID, FirstName, MiddleName, LastName, Gender, DOB)
VALUES (@ChildID, @FirstName, @MiddleName, @LastName, @Gender, @DOB)
I was hoping it would just leave the final 2 columns blank, for them to be filled out later, but all it does is give me an error. 我希望它将最后两列留为空白,以便稍后填写,但是这样做只是给我一个错误。
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__Child__ChildGuar__2B3F6F97". The conflict occurred in database "ChildCare", table "dbo.ChildGuardian", column 'ChildGuardianID'.
I can re-work the database a little, if necessary. 如有必要,我可以稍微修改数据库。
Have you tried passing in NULL
for those values? 您是否尝试过为这些值传递
NULL
? You shouldn't have to pass anything, but it may help with troubleshooting. 您无需传递任何内容,但可能有助于解决问题。
I'd also check that Child.ChildGuardianID
isn't an identity, and that it doesn't have a default value. 我还将检查
Child.ChildGuardianID
不是身份,并且它没有默认值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.