[英]The INSERT statement conflicted with the FOREIGN KEY constraint - asp.net.mvc5
當我嘗試將數據插入門票表時出現該錯誤:
INSERT 語句與 FOREIGN KEY 約束“FK_dbo.Tickets_dbo.Screenings_Date_HallId”沖突。 沖突發生在數據庫“aspnet-CinemaProject-20210105112627”的表“dbo.Screenings”中。 該語句已終止。
public class Ticket
{
[Key]
[Column(Order = 1)]
public short SeatNumber { get; set; }
[ForeignKey("Date, HallId")]
public Screening Screening { get; set; }
[Key]
[Column(Order = 2)]
public DateTime? Date { get; set; }
[Key]
[Column(Order = 3)]
public byte HallId { get; set; }
public DateTime? CreationTime { get; set; }
public bool Paid { get; set; }
}
.
public class Screening
{
[Key]
[Column(Order = 1)]
public DateTime? Date { get; set; }
[ForeignKey("MovieId")]
public Movie Movie { get; set; }
[Required]
public int MovieId { get; set; }
[ForeignKey("HallId")]
public Hall Hall { get; set; }
[Key]
[Column(Order = 2)]
[Required]
[Display(Name = "Hall")]
public byte HallId { get; set; }
[Required]
public short Price { get; set; }
}
.
public class Hall
{
public byte Id { get; set; }
}
誰能幫我?
編輯:
(篩選表)^^
發生錯誤是因為您嘗試作為外鍵插入“Ticket”表中的日期在“screening”表中不存在作為主鍵
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.