I have tables called tbScore
, tbScoreDetail
and tbReview
. I have a foreign key column reviewId
(nullable) in tbScoreDetail
. It will allow me to insert the row, but while updating the table, it is throwing an exception
The UPDATE statement conflicted with foreign key constraint "FK_Review_ScoreDetail"
This is my code:
public class ScoreDetail
{
public int ScoreDetailId { get; set; }
public int ScoreId { get; set; }
public int? ReviewId { get; set; }
}
public class ReviewId
{
public int ReviewId { get; set; }
public string Review { get; set; }
}
Your problem is related to your mapping settings in the EntityFramework, why do I say this is where the foreign keys are configured and whether or not they are nullable is commanded or by:
public int? IndexNullable { get; set ;}
Or in the configs where you can configure this way https://www.entityframeworktutorial.net/code-first/configure-entity-mappings-using-fluent-api.aspx
What it takes to check how your keys are configured in your default entity correctly and the index by your own nomenclature see the keys too and the index on your own when migrations perceive a database of your indexes and very likely that a cases, where an index was created without its explicit intention.