【问题标题】:Specified key was too long; max key length is 767 bytes mysql , entityframework(migration)指定的密钥太长;最大密钥长度为 767 字节 mysql , entityframework(migration)
【发布时间】:2017-11-23 05:51:57
【问题描述】:

我正在尝试将 MySql 和 EntityFramework 与 Migrations 一起使用,但似乎有问题。

抛出此异常:
指定的密钥太长;最大密钥长度为 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());

    }}

【问题讨论】:

  • 对象的常用键值是什么样的?之前的键列是另一种类型吗?
  • @DevilSuichiro 我所有类中的键都是这样的代码: [Key] [Column ("id")] Public int Id {get;放; }

标签: mysql entity-framework migration


【解决方案1】:

试试这个:

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

【讨论】:

  • 我使用了您的代码,但它不起作用。现在我有这个错误:找不到文件:'./pmt_db/dbo@002epriorit@0kt@002dintegrationsart.frm' (errno: 2) integrationsart is a table in database
  • 我忘了说,我把表改名了
猜你喜欢
  • 2016-10-04
  • 2016-04-15
  • 2012-05-31
  • 2017-02-01
  • 2015-06-22
  • 2013-12-21
  • 2015-06-29
  • 2019-02-21
  • 2020-09-10
相关资源
最近更新 更多