C#C
C#4y ago
Alerin

Error Introducing FOREIGN KEY constraint

An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Introducing FOREIGN KEY constraint 'FK_Identity.Roles_Identity.User_UserId' on table 'Identity.Roles' 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 or index. See previous errors.


Models:
public class Roles
{
    public int Id { get; set; }
    public User User { get; set; } = null!;
    public Guid UserId { get; set; }
    public Role Role { get; set; } = null!;
    public int RoleId { get; set; }
}

public class Role
{
    public int Id { get; set; }
    public string Name { get; set; } = string.Empty;
    public ICollection<RolePolicy> Permission { get; set; } = new List<RolePolicy>();
}

public class RolePolicy
{
    public int Id { get; set; }
    public Role Role { get; set; } = null!;
    public int RoleId { get; set; }
    public string Policy { get; set; } = string.Empty;
}

public class User
{
    [Key]
    public Guid Id { get; set; }

    [StringLength(16, MinimumLength = 4), Required]
    public string Name { get; set; } = string.Empty;                                   

    ...

    public Role DisplayGroup { get; set; } = null!;                                     
    public int DisplayGroupId { get; set; }
    public ICollection<Roles> Roles { get; set; } = new List<Roles>(); 
Was this page helpful?