我正在尝试将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());
}}
试试这个:
[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class PmtDbContext : DbContext
{
static PmtDbContext()
{
Database.SetInitializer(
new MigrateDatabaseToLatestVersion<PmtDbContext, Migrations.Configuration>());
}
}