I just updated the Microsoft.AspNet.Identity.EntityFramework library to the latest version (2.0.0.0), and I found some errors when creating the tables. When I generate the migration code (Up and Down methods), I canโt upload the changes to the beacuse database due to an index problem while running the "Updata-Database"
The specified key was too long; The maximum key length is 767 bytes.
Code to execute:
public override void Up() { CreateTable( "dbo.AspNetRoles", c => new { Id = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"), Name = c.String(nullable: false, maxLength: 256, storeType: "nvarchar"), }) .PrimaryKey(t => t.Id) .Index(t => t.Name, unique: true, name: "RoleNameIndex"); CreateTable( "dbo.AspNetUserRoles", c => new { UserId = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"), RoleId = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"), }) .PrimaryKey(t => new { t.UserId, t.RoleId }) .ForeignKey("dbo.AspNetRoles", t => t.RoleId, cascadeDelete: true) .ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true) .Index(t => t.UserId) .Index(t => t.RoleId); CreateTable( "dbo.AspNetUsers", c => new { Id = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"), Email = c.String(maxLength: 256, storeType: "nvarchar"), EmailConfirmed = c.Boolean(nullable: false), PasswordHash = c.String(maxLength: 256, storeType: "nvarchar"), SecurityStamp = c.String(maxLength: 256, storeType: "nvarchar"), PhoneNumber = c.String(maxLength: 256, storeType: "nvarchar"), PhoneNumberConfirmed = c.Boolean(nullable: false), TwoFactorEnabled = c.Boolean(nullable: false), LockoutEndDateUtc = c.DateTime(precision: 0), LockoutEnabled = c.Boolean(nullable: false), AccessFailedCount = c.Int(nullable: false), UserName = c.String(nullable: false, maxLength: 256, storeType: "nvarchar"), }) .PrimaryKey(t => t.Id) .Index(t => t.UserName, unique: true, name: "UserNameIndex"); CreateTable( "dbo.AspNetUserClaims", c => new { Id = c.Int(nullable: false, identity: true), UserId = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"), ClaimType = c.String(maxLength: 256, storeType: "nvarchar"), ClaimValue = c.String(maxLength: 256, storeType: "nvarchar"), }) .PrimaryKey(t => t.Id) .ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true) .Index(t => t.UserId); CreateTable( "dbo.AspNetUserLogins", c => new { LoginProvider = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"), ProviderKey = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"), UserId = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"), }) .PrimaryKey(t => new { t.LoginProvider, t.ProviderKey, t.UserId }) .ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true) .Index(t => t.UserId); } public override void Down() { DropForeignKey("dbo.AspNetUserRoles", "UserId", "dbo.AspNetUsers"); DropForeignKey("dbo.AspNetUserLogins", "UserId", "dbo.AspNetUsers"); DropForeignKey("dbo.AspNetUserClaims", "UserId", "dbo.AspNetUsers"); DropForeignKey("dbo.AspNetUserRoles", "RoleId", "dbo.AspNetRoles"); DropIndex("dbo.AspNetUserLogins", new[] { "UserId" }); DropIndex("dbo.AspNetUserClaims", new[] { "UserId" }); DropIndex("dbo.AspNetUsers", "UserNameIndex"); DropIndex("dbo.AspNetUserRoles", new[] { "RoleId" }); DropIndex("dbo.AspNetUserRoles", new[] { "UserId" }); DropIndex("dbo.AspNetRoles", "RoleNameIndex"); DropTable("dbo.AspNetUserLogins"); DropTable("dbo.AspNetUserClaims"); DropTable("dbo.AspNetUsers"); DropTable("dbo.AspNetUserRoles"); DropTable("dbo.AspNetRoles"); }
When I use versiรณn 1.0.0.0 from Microsoft.AspNet.Identity.EntityFramework, the code for updating the database is different and I have no problem.
public override void Up() { CreateTable( "dbo.AspNetRoles", c => new { Id = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"), Name = c.String(nullable: false, maxLength: 256, storeType: "nvarchar"), }) .PrimaryKey(t => t.Id); CreateTable( "dbo.AspNetUsers", c => new { Id = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"), UserName = c.String(maxLength: 256, storeType: "nvarchar"), PasswordHash = c.String(maxLength: 256, storeType: "nvarchar"), SecurityStamp = c.String(maxLength: 256, storeType: "nvarchar"), Discriminator = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"), }) .PrimaryKey(t => t.Id); CreateTable( "dbo.AspNetUserClaims", c => new { Id = c.Int(nullable: false, identity: true), ClaimType = c.String(maxLength: 256, storeType: "nvarchar"), ClaimValue = c.String(maxLength: 256, storeType: "nvarchar"), User_Id = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"), }) .PrimaryKey(t => t.Id) .ForeignKey("dbo.AspNetUsers", t => t.User_Id, cascadeDelete: true) .Index(t => t.User_Id); CreateTable( "dbo.AspNetUserLogins", c => new { UserId = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"), LoginProvider = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"), ProviderKey = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"), }) .PrimaryKey(t => new { t.UserId, t.LoginProvider, t.ProviderKey }) .ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true) .Index(t => t.UserId); CreateTable( "dbo.AspNetUserRoles", c => new { UserId = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"), RoleId = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"), }) .PrimaryKey(t => new { t.UserId, t.RoleId }) .ForeignKey("dbo.AspNetRoles", t => t.RoleId, cascadeDelete: true) .ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true) .Index(t => t.UserId) .Index(t => t.RoleId); } public override void Down() { DropForeignKey("dbo.AspNetUserRoles", "UserId", "dbo.AspNetUsers"); DropForeignKey("dbo.AspNetUserLogins", "UserId", "dbo.AspNetUsers"); DropForeignKey("dbo.AspNetUserClaims", "UserId", "dbo.AspNetUsers"); DropForeignKey("dbo.AspNetUserRoles", "RoleId", "dbo.AspNetRoles"); DropIndex("dbo.AspNetUserLogins", new[] { "UserId" }); DropIndex("dbo.AspNetUserClaims", new[] { "UserId" }); DropIndex("dbo.AspNetUsers", "UserNameIndex"); DropIndex("dbo.AspNetUserRoles", new[] { "RoleId" }); DropIndex("dbo.AspNetUserRoles", new[] { "UserId" }); DropIndex("dbo.AspNetRoles", "RoleNameIndex"); DropTable("dbo.AspNetUserLogins"); DropTable("dbo.AspNetUserClaims"); DropTable("dbo.AspNetUsers"); DropTable("dbo.AspNetUserRoles"); DropTable("dbo.AspNetRoles"); }
Can someone help me try to solve the problem?
Thanks in advance!