I am trying to have a model with two references to another model.
I have researched this error, but have seen suggestions relating to previous .Net Core versions.
Below is the model
public class Match
{
public int ID { get; set; }
public DateTime MatchDateTime
{ get; set; }
public int LocationID { get; set; }
public int GroupID { get; set; }
public int HomeTeamScore { get; set; }
public int AwayTeamScore { get; set; }
[Required]
public int HomeTeamID { get; set; }
public int AwayTeamID { get; set; }
public Location Location { get; set; }
public Group Group { get; set; }
[Required]
[ForeignKey("HomeTeamID")]
public Team HomeTeam { get; set; }
[ForeignKey("AwayTeamID")]
public Team AwayTeam { get; set; }
}
Upon running the migration, i get this error:
Introducing FOREIGN KEY constraint 'FK_Matches_Teams_AwayTeamID' on table 'Matches' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
OnModelCreatingmethod contents (since you're stated using Code First migrations)? I think you have problem inmodelBuilder.Entity<Match>relationship which may declared more than once, causing multiple cycles or cascade paths.Teamcan't both have cascaded delete.