指定密钥太长;最大密钥长度为767字节mysql,entityframework(migration)

时间:2017-06-20 15:29:05

标签: mysql entity-framework migration

我尝试使用MySql和EntityFramework进行迁移,但似乎有些错误。

抛出此异常:
指定密钥太长;最大密钥长度为767字节

请帮助我:(

我的新课程:

public class user
{
    public user()
    {
    }

    [Key]
    [Column("id")]
    public int Id { get; set; }

    [StringLength(20)]
    [Column("name")]
    public string Name { get; set; }

    [Column("age")]
    public int Age { get; set; }

}





public class PmtDbContext : DbContext
{
    static PmtDbContext()
    {
       Database.SetInitializer(new MigrateDatabaseToLatestVersion<PmtDbContext, Migrations.Configuration>());

    }}





internal sealed class Configuration : DbMigrationsConfiguration<PmtDbContext>
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = true;
        AutomaticMigrationDataLossAllowed = true;
        SetSqlGenerator("MySql.Data.MySqlClient", new MySqlMigrationSqlGenerator());

    }}

1 个答案:

答案 0 :(得分:-2)

试试这个:

[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class PmtDbContext : DbContext
{
    static PmtDbContext()
    {
        Database.SetInitializer(
            new MigrateDatabaseToLatestVersion<PmtDbContext, Migrations.Configuration>());
    }
}