在table'ReservedSeats'上引入FOREIGN KEY约束'FK_ReservedSeats_Seats_SeatId'可能会造成循环或多级联路径
Introducing FOREIGN KEY constraint 'FK_ReservedSeats_Seats_SeatId' on table 'ReservedSeats' may cause cycles or multiple cascade paths
我有一个电影院预订系统的数据库。
尝试使用 Seats 和 ReservedSeats 表更新数据库时出错:
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.
座椅型号:
[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; }
预留座位:
[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; }
筛选:
[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; }
预订:
[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; }
电影:
[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; }
礼堂:
[Key]
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public int SeatsNo { get; set; }
流派只有 ID、名称和描述。
应用用户:
public string Name { get; set; }
[NotMapped]
public string Role { get; set; }
应用程序数据库上下文:
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核心版本:3.1.7
我去了我创建预留席位的迁移 Table 并且对于 SeatEd FK 我添加了 noAction onDelete 和 noAction onUpdate。
table.ForeignKey(
name: "FK_ReservedSeats_Seats_SeatId",
column: x => x.SeatId,
principalTable: "Seats",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction,
onUpdate: ReferentialAction.NoAction);
我有一个电影院预订系统的数据库。
尝试使用 Seats 和 ReservedSeats 表更新数据库时出错:
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.
座椅型号:
[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; }
预留座位:
[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; }
筛选:
[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; }
预订:
[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; }
电影:
[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; }
礼堂:
[Key]
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public int SeatsNo { get; set; }
流派只有 ID、名称和描述。
应用用户:
public string Name { get; set; }
[NotMapped]
public string Role { get; set; }
应用程序数据库上下文:
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核心版本:3.1.7
我去了我创建预留席位的迁移 Table 并且对于 SeatEd FK 我添加了 noAction onDelete 和 noAction onUpdate。
table.ForeignKey(
name: "FK_ReservedSeats_Seats_SeatId",
column: x => x.SeatId,
principalTable: "Seats",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction,
onUpdate: ReferentialAction.NoAction);