【发布时间】:2023-03-22 11:24:01
【问题描述】:
我在运行迁移时使用 Code First,但出现错误。
在表“用户”上引入 FOREIGN KEY 约束“FK_dbo.Users_dbo.Campaigns_CampaignID”可能会导致循环或多个级联路径。指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他 FOREIGN KEY 约束。 无法创建约束。查看以前的错误。
拜托,我需要帮助,我不明白为什么会发生这个错误。
我看到了其他类似的出版物,但我无法解决我的问题。
谢谢,
public class User
{
public int ID { get; set; }
[StringLength(50, MinimumLength = 3)]
public string UserName { get; set; }
public string Password { get; set; }
[StringLength(50, MinimumLength = 3)]
public int CityID { get; set; }
public virtual City City { get; set; }
public int CampaignID { get; set; }
public virtual Campaign Campaign { get; set; }
public int RoomID { get; set; }
public virtual Room Room { get; set; }
public bool Status { get; set; }
public DateTime RegisterDate { get; set; }
public int UserCreator { get; set; }
}
public class City
{
public int ID { get; set; }
[StringLength(50, MinimumLength = 3)]
public string Name { get; set; }
public virtual ICollection Users { get; set; }
}
public class Campaign
{
public int ID { get; set; }
[StringLength(50, MinimumLength = 3)]
public string Name { get; set; }
public int CompanyID { get; set; }
public virtual Company Company { get; set; }
public virtual ICollection Users { get; set; }
public virtual ICollection Rooms { get; set; }
}
public class Company
{
public int ID { get; set; }
[StringLength(30, MinimumLength = 3)]
public string Name { get; set; }
public virtual ICollection Campaigns { get; set; }
}
public class Room
{
public int ID { get; set; }
[MaxLength(200)]
public string RoomKey { get; set; }
[StringLength(30, MinimumLength = 3)]
public string Name { get; set; }
public int UserCreator { get; set; }
public virtual User User { get; set; }
public int CampaignID { get; set; }
public virtual Campaign Campaign { get; set; }
public virtual ICollection Messages { get; set; }
}
public class Message
{
public int ID { get; set; }
public string Content { get; set; }
public string Timestamp { get; set; }
public int UserID { get; set; }
public virtual User User { get; set; }
public int RoomID { get; set; }
public virtual Room Room { get; set; }
}
【问题讨论】: