【问题标题】:Entity Framework "Specified key was too long; max key length is 1000 bytes"实体框架“指定的密钥太长;最大密钥长度为 1000 字节”
【发布时间】:2018-02-01 00:17:16
【问题描述】:

我有一个使用asp.net-core 2.0 构建的应用程序。

我使用Pomelo.EntityFrameworkCore.MySql来集成MySql。

我在 Startup.cs 中使用的配置是:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<ApplicationDbContext>(options => options.UseMySql("Server=localhost;port=3306;database=MyDB;user=MyDb_user;password=test123");
    ...
}

框架自带的ApplicationUserDbContext如下:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options)
    {
    }

    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);
    }
}

现在在 MySql 中,我使用排序规则“utf8_general_ci”创建了 MyDB。

但在 DB 迁移时我收到错误:

'Specified key was too long; max key length is 1000 bytes'

我发现使用 utf8 的所有解决方案都不适用于 asp.net-core 2.0

asp.net-core 2.0 有什么解决方案

【问题讨论】:

标签: c# mysql entity-framework asp.net-core asp.net-core-2.0


【解决方案1】:
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("SET default_storage_engine=INNODB");
}

Ability to specify engine, charset, ROW_FORMAT and more

【讨论】:

    猜你喜欢
    • 2010-11-05
    • 2011-09-03
    • 2012-02-03
    • 1970-01-01
    • 2012-08-04
    • 2017-02-27
    • 2017-03-13
    相关资源
    最近更新 更多