1
遷移錯誤這裏是我的ApplicationRole:在Asp.Net創造AspNetRoles表自定義字段時標識2.0.0
public class ApplicationRole : IdentityRole
{
[Required]
[StringLength(50)]
public string ProperName { get; set; }
public string Description { get; set; }
}
這裏是我的ApplicationDbContext:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
}
這裏是遷移添加 - 創建的遷移:
namespace MyApp.MigrationsMembership
{
using System;
using System.Data.Entity.Migrations;
public partial class RolesFields : DbMigration
{
public override void Up()
{
DropForeignKey("dbo.AspNetUserRoles", "RoleId", "dbo.AspNetRoles");
CreateTable(
"dbo.AspNetRoles",
c => new
{
Id = c.String(nullable: false, maxLength: 128),
ProperName = c.String(nullable: false, maxLength: 50),
Description = c.String(),
Name = c.String(nullable: false, maxLength: 256),
})
.PrimaryKey(t => t.Id);
AddForeignKey("dbo.AspNetUserRoles", "RoleId", "dbo.AspNetRoles", "Id", cascadeDelete: true);
DropTable("dbo.AspNetRoles");
}
public override void Down()
{
CreateTable(
"dbo.AspNetRoles",
c => new
{
Id = c.String(nullable: false, maxLength: 128),
Name = c.String(nullable: false, maxLength: 256),
})
.PrimaryKey(t => t.Id);
DropForeignKey("dbo.AspNetUserRoles", "RoleId", "dbo.AspNetRoles");
DropTable("dbo.AspNetRoles");
AddForeignKey("dbo.AspNetUserRoles", "RoleId", "dbo.AspNetRoles", "Id", cascadeDelete: true);
}
}
}
爲什麼它創建一個新的AspNetRoles表...然後嘗試刪除表上呢?
下面是從包管理器控制檯中的錯誤消息:
更新:我去掉「測試版」,從標題,因爲同樣的問題繼續發生,因爲2.0.0發佈。我創建的每個遷移都需要刪除一個表,最後纔是DropTable
。
問題可能出現,因爲我啓用了遷移使用Microsoft.AspNet.Identity.Core 1.0.0.0,然後更新到版本2.0.0.0-beta1;其中還將EntityFramework更新爲測試版。 –
我剛剛開始使用版本1,將等待版本2,而不是使用測試版。我將把這個問題留給實體框架和/或asp.net身份人員進行測試。 –