我尝试使用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());
}}
答案 0 :(得分:-2)
试试这个:
[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class PmtDbContext : DbContext
{
static PmtDbContext()
{
Database.SetInitializer(
new MigrateDatabaseToLatestVersion<PmtDbContext, Migrations.Configuration>());
}
}