I have a database for a Cinema Reservation System.
Error when trying to update-database with the Seats and ReservedSeats tables:
Introducing FOREIGN KEY constraint 'FK_ReservedSeats_Seats_SeatId' on table 'ReservedSeats' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create constraint. See previous errors.
The model for Seat:
[Key]
public int Id { get; set; }
[Required]
public int Row { get; set; }
[Required]
public int Number { get; set; }
[Required]
public int AuditoriumId { get; set; }
[ForeignKey("AuditoriumId")]
public Auditorium Auditorium { get; set; }
ReservedSeat:
[Key]
public int Id { get; set; }
public int SeatId { get; set; }
[ForeignKey("SeatId")]
public Seat Seat { get; set; }
public int ScreeningId { get; set; }
[ForeignKey("ScreeningId")]
public Screening Screening { get; set; }
public int ReservationId { get; set; }
[ForeignKey("ResevationId")]
public Reservation Reservation { get; set; }
public bool isReserved { get; set; }
Screening:
[Key]
public int Id { get; set; }
[Required]
public int MovieId { get; set; }
[ForeignKey("MovieId")]
public Movie Movie { get; set; }
[Required]
public int AuditoriumId { get; set; }
[ForeignKey("AuditoriumId")]
public Auditorium Auditorium { get; set; }
[Required]
public string ScreeningStart { get; set; }
[Required]
public double TicketPrice { get; set; }
public string WeekDay { get; set; }
Reservation:
[Key]
public int Id { get; set; }
public int ScreeningId { get; set; }
[ForeignKey("ScreeningId")]
public Screening Screening { get; set; }
public IEnumerable<ReservedSeat> ReservedSeats { get; set; }
public string UserId { get; set; }
[ForeignKey("UserId")]
public ApplicationUser User { get; set; }
public double AmountToPay { get; set; }
public bool isPaid { get; set; }
public bool isCanceled { get; set; }
Movie:
[Key]
public int Id { get; set; }
[Required]
public string Title { get; set; }
public string Director { get; set; }
public string Description { get; set; }
[Display(Name="Running Time")]
public int RunningTimeMin { get; set; }
public int GenreId { get; set; }
[ForeignKey("GenreId")]
public Genre Genre { get; set; }
public string ImageUrl { get; set; }
Auditorium:
[Key]
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public int SeatsNo { get; set; }
Genre only has id, name and description.
Application user:
public string Name { get; set; }
[NotMapped]
public string Role { get; set; }
Application Db Context:
public DbSet<Movie> Movies { get; set; }
public DbSet<Genre> Genres { get; set; }
public DbSet<Auditorium> Auditoriums { get; set; }
public DbSet<Screening> Screenings { get; set; }
public DbSet<Seat> Seats { get; set; }
public DbSet<ApplicationUser> ApplicationUsers { get; set; }
public DbSet<ReservedSeat> ReservedSeats { get; set; }
public DbSet<Reservation> Reservations { get; set; }
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
Ef core version: 3.1.7