내 앱을 ASP.Net Core 2.0으로 마이그레이션하고 있습니다.Auth를 Core 2.0으로 마이그레이션 : 엔티티 유형 'IdentityUserRole <int>'에 기본 키가 정의되어 있어야합니다.
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
builder.Entity<ApplicationUser>()
.HasMany(e => e.Claims)
.WithOne()
.HasForeignKey(e => e.UserId)
.IsRequired()
.OnDelete(DeleteBehavior.Cascade);
builder.Entity<ApplicationUser>()
.HasMany(e => e.Logins)
.WithOne()
.HasForeignKey(e => e.UserId)
.IsRequired()
.OnDelete(DeleteBehavior.Cascade);
builder.Entity<ApplicationUser>()
.HasMany(e => e.Roles)
.WithOne()
.HasForeignKey(e => e.UserId)
.IsRequired()
.OnDelete(DeleteBehavior.Cascade);
}
그것은 나에게 잘 보이는 : 위의 문서에서
https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x
, 그것은 다음과 같은 매핑을 가지고있다. 매핑에 문제가public class ApplicationUser : IdentityUser
{
/// <summary>
/// Navigation property for the roles this user belongs to.
/// </summary>
public virtual ICollection<IdentityUserRole<int>> Roles { get; } = new List<IdentityUserRole<int>>();
/// <summary>
/// Navigation property for the claims this user possesses.
/// </summary>
public virtual ICollection<IdentityUserClaim<int>> Claims { get; } = new List<IdentityUserClaim<int>>();
/// <summary>
/// Navigation property for this users login accounts.
/// </summary>
public virtual ICollection<IdentityUserLogin<int>> Logins { get; } = new List<IdentityUserLogin<int>>();
public string FullName { get; set; }
}
거기에 다음과 같이
The entity type 'IdentityUserRole' requires a primary key to be defined.
ApplicationUser가 정의 : 그러나, 나는 다음과 같은 오류가
dotnet ef migrations add InitialCreate
실행?
을 추가? –
코드가 없습니다. 그러나 여기에 대한 문서가 있습니다. https://docs.microsoft.com/en-us/aspnet/core/api/microsoft.aspnetcore.identity.entityframeworkcore.identityuserrole-1 –
@JonasArcangel이 문제를 알아 냈습니까? GUID 기본 키를 int로 전환하려고합니다. 1.1에서는 사용할 수 있었지만 2.0에서는 사용할 수 없었습니다. 'ApplicationUser'가'IdentityUser'에서 상속 받아야한다고 생각하십시오.이 [github issue] (https://github.com/aspnet/Identity/issues/780)가 도움이 될 수 있습니다. –