前段时间,我创建了一个具有Identity 1.0版本的ASP.NET MVC 5网站,并且我创建了该项目的Identity表.现在我必须使其他网站使用相同的数据库进行身份验证,但现在身份版本是2.0.
所以当我尝试在新网站进行身份验证时,我会收到一些错误.
所以当我尝试在新网站进行身份验证时,我会收到一些错误.
我试图使用Migrations方法迁移数据库,但它困惑和获取此错误数据库中已经有一个名为“AspNetRoles”的对象.当我在PM控制台中键入Update-Database.
解决方法
Add-Migration InitialMigrations -IgnoreChanges
这应该会生成一个空白的“InitialMigration”文件.现在,添加任何所需的更改到你想要的类.添加更改后,再次运行update命令:
update-database -verbose
现在将应用自动迁移,并且您的更改将更改表.
编辑:
以下是将身份1迁移到2 Upgrading from ASP.NET.Identity 1.0 to 2.0的解决方案
使用此手动迁移
public override void Up() { RenameColumn(table: "dbo.AspNetUserClaims",name: "User_Id",newName: "UserId"); RenameIndex(table: "dbo.AspNetUserClaims",name: "IX_User_Id",newName: "IX_UserId"); DropPrimaryKey("dbo.AspNetUserLogins"); AddColumn("dbo.AspNetUsers","Email",c => c.String(maxLength: 256)); AddColumn("dbo.AspNetUsers","EmailConfirmed",c => c.Boolean(nullable: false)); AddColumn("dbo.AspNetUsers","PhoneNumber",c => c.String()); AddColumn("dbo.AspNetUsers","PhoneNumberConfirmed","TwoFactorEnabled","LockoutEndDateUtc",c => c.DateTime()); AddColumn("dbo.AspNetUsers","LockoutEnabled","AccessFailedCount",c => c.Int(nullable: false)); AlterColumn("dbo.AspNetUsers","UserName",c => c.String(nullable: false,maxLength: 256)); AlterColumn("dbo.AspNetUsers","FirstName",c => c.String(nullable: false)); AlterColumn("dbo.AspNetUsers","LastName",c => c.String(nullable: false)); AddColumn("dbo.AspNetUsers","CreatedDateTime",c => c.DateTime(nullable: false)); AlterColumn("dbo.AspNetRoles","Name",maxLength: 256)); AddPrimaryKey("dbo.AspNetUserLogins",new[] { "LoginProvider","ProviderKey","UserId" }); CreateIndex("dbo.AspNetUsers",unique: true,name: "UserNameIndex"); CreateIndex("dbo.AspNetRoles",name: "RoleNameIndex"); DropColumn("dbo.AspNetUsers","Discriminator"); }