可能会导致循环或多个级联路径。指定ON DELETE NO ACTION或ON UPDATE NO ACTION,或修改其他FOREIGN KEY约束

时间:2018-09-11 05:04:40

标签: entity-framework asp.net-core migration entity-framework-core ef-core-2.0

实体框架核心

在执行更新数据库时抛出错误

错误:- 在表'UserRoleRelationship'上引入FOREIGN KEY约束'FK_UserRoleRelationship_UserRoels_ParentUserRoleId'可能会导致循环或多个级联路径。指定ON DELETE NO ACTION或ON UPDATE NO ACTION,或修改其他FOREIGN KEY约束。 无法创建约束或索引。

public class UserRoleRelationship 
{
    [Key]
    public int Id { get; set; }
    [Required]
    public Guid UserRoleRelationshipId { get; set; }

    public virtual UserRole ChildUserRole { get; set; }
    public int ChildUserRoleId { get; set; }

    public virtual UserRole ParentUserRole { get; set; }
    public int ParentUserRoleId { get; set; }

}

public class UserRole 
{
    [Key]
    public int Id { get; set; }
    [Required]
    public Guid UserRoleId { get; set; }
    public virtual Role Role { set; get; }
    public int RoleId { set; get; }
    public virtual U.User User { set; get; }
    public int UserId { set; get; }
}

1 个答案:

答案 0 :(得分:0)

要解决此问题,请尝试将int设置为int?如下所示:

公共诠释? ParentUserRoleId {get;组; }