The INSERT statement conflicted with the FOREIGN KEY constraint error

折月煮酒 提交于 2019-12-01 18:06:23
SamekaTV

You are probably trying to access or insert using a non-existent foreign key. Go to your dbo.Contacts Table and look for the record with that key. You'll find no record with that key in the table. You need to create a record with that key or use another (existent) key.

If you are creating the FK obect as well than you should first store it and retrieve its ID, failing todo so will cause the FK_Key to fail as you have no FK value.

Walter

If you want you can allow to reference to non-existent records

Sql("ALTER TABLE dbo.Users NOCHECK CONSTRAINT [FK_dbo.Users_dbo.Roles_RoleID]");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!