SqlException: The INSERT statement conflicted with the FOREIGN KEY
Guys, I have this error in ASP.NET 8
"Internal Exception 1:
SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_RegistrationFormModels_SportModel_SportId". The conflict occurred in database "RegistrationFormDb", table "dbo.SportModel", column 'Id'."
I am inserting the value 2 in this sport_id, but this value 2 exists in the bank. I don't know why it's giving this error
4 Replies
are you using C# with dapper or EF? the fk is correctly bonded with pk_sport_Id?
I'm using EF.
I'm not sure, my model is like this
show code
sport_id
doesn't follow convention for what a foreign key should be named in EF, so this won't work unless you did some entity configuration that you have not shared