身份实体框架库 - 更新数据库[MySQL] [英] Identity Entity Framework Library - Update Database [MySQL]
问题描述
我刚刚将库Microsoft.AspNet.Identity.EntityFramework更新到最后一个版本(2.0.0.0),我发现创建表的一些错误。当我生成迁移代码(Up和Down方法)时,当我执行Updata-Database时,我无法将更改上传到数据库中,我有一个索引问题。
I just updated the library Microsoft.AspNet.Identity.EntityFramework to the last version (2.0.0.0) and I have found some errors creating the tables. When I generate the migration code (Up and Down methods), I can't upload the changes to the database beacuse of I have a problem with indexs when I execute the "Updata-Database"
指定的键太长;最大密钥长度为767字节
Specified key was too long; max key length is 767 bytes
要执行的代码:
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");
}
当我使用Microsoft.AspNet.Identity.EntityFramework的versión1.0.0.0更新数据库的代码是不同的,我没有任何问题
When I use the versión 1.0.0.0 of Microsoft.AspNet.Identity.EntityFramework the code to update the database is different and I don't have any 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 anyone help me try to solve the problem?
提前感谢
推荐答案
您可能需要查看本教程: http:// www .asp.net / mvc / tutorials / security / aspnet-identity-using-mysql-storage-with-a-entityframework-mysql-provider
- 具体说明添加自定义MigrationHistory上下文如何设置一个自定义的HistoryContext来解决主键大小问题。
You may want to check out this tutorial: http://www.asp.net/mvc/tutorials/security/aspnet-identity-using-mysql-storage-with-an-entityframework-mysql-provider - specifically the section "Adding custom MigrationHistory context" which explains how to set a custom HistoryContext to get around the primary key size problem.
这篇关于身份实体框架库 - 更新数据库[MySQL]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!