Skip to content Skip to sidebar Skip to footer

In Code First The Insert Statement Conflicted With The Foreign Key Constraint

I just started using Code first approach for creating databases. I have following 3 tables : public partial class AccountHolder { public int AccountHolderId { get; set; }

Solution 1:

In your table dbo.AccountHolders and dbo.Nominees, it has a foreign key reference to another table. The way a FK works is it cannot have a value in that column that is not also in the primary key column of the referenced table.

If you have SQL Server Management Studio, open it up and sp_help 'dbo.dbo.Nominees'. See which column that FK is on, and which column of which table it references. You're inserting some bad data.Do the same for sp_help 'dbo.dbo.AccountHolders '.

Hope this helps.

Post a Comment for "In Code First The Insert Statement Conflicted With The Foreign Key Constraint"