实体框架“指定密钥太长;最大密钥长度为1000字节”

时间:2017-08-23 12:01:50

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

我有一个使用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");
    ...
}

框架附带的DbContext ApplicationUser如下所示:

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中我使用Collat​​ion创建了MyDB“utf8_general_ci”。

但是在数据库迁移时我收到错误:

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

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

asp.net-core 2.0

是否有任何解决方案

1 个答案:

答案 0 :(得分:0)

protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("SET default_storage_engine=INNODB");
}

Ability to specify engine, charset, ROW_FORMAT and more