2017-06-20 117 views
0

我試圖使用MySql和EntityFramework遷移,但似乎是錯誤的東西。指定的密鑰太長;最大密鑰長度是767字節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

爲對象做什麼平常鍵值的樣子?是以前的另一個類型的關鍵列? – DevilSuichiro

+0

@DevilSuichiro我所有班級的鑰匙都是這樣的代碼: [Key] [Col umn(「id」)] public int Id {get;組; } – Mahrooy

回答

-2

試試這個:

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

我用你的代碼,但它沒有工作。現在我有這個錯誤: 找不到文件:'./pmt_db/[email protected]@[email protected]'(errno:2) integrationsart是數據庫中的表 – Mahrooy

+0

我忘了說,我有桌子改名 – Mahrooy

相關問題