无法将代码首次迁移到mysql数据库 [英] Unable to apply code first migrations to mysql database
问题描述
PM>启用迁移
PM>添加迁移初始迁移
PM> update-database -verbose
这些步骤将Migration文件夹创建到我的项目,并在Migration文件夹中创建配置timestamp_Initialmigration文件,在配置文件中我添加了以下代码。
SetSqlGenerator(MySql.Data.MySqlClient,新的MySql.Data .Entity.MySqlMigrationSqlGenerator());
之后,我已经将一个字段添加到我的课堂,如
public int newprop {get; set;}
之后,我在PM控制台中执行update-database -verbose命令。
当我执行我的应用程序时,会抛出一个错误,如
未知列'Extent1.newprop'字段列表'
请指导我为什么我得到这个错误我去错了的方式请指导我。
如果您不使用自动迁移
Database.SetInitializer(new MigrateDatabaseToLatestVersion()); / p>
public class MyMigrationConfiguration:DbMigrationsConfiguration< MyDbContext>
{
public MyMigrationConfiguration()
{
AutomaticMigrationsEnabled = true;你在用这个
AutomaticMigrationDataLossAllowed = true;
}
}
然后,您需要使用PM Commandlet添加另一个迁移并更新数据库。
PM>启用迁移//已经完成了?
PM>添加迁移myLabel
PM>更新数据库
在网络上搜索基于代码的迁移以获取帮助
I am working on asp.net mvc with EF code first model. I am trying to apply migrations using EF code first to my project. I am using MySql database. currently i am using EF 4.3.1 version and mysql connector/.net of 6.6.4.0 version. I am successfully add migrations to my project that means i execute series of commands that gave no errors for me. I have followed these steps,
PM> Enable-Migrations
PM> Add-Migration InitialMigration
PM> update-database -verbose
these steps create Migration folder to my project and inside Migration folder it creates configuration and timestamp_Initialmigration files, in configuration file i have added following code.
SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
after that i have added one field to my class like,
public int newprop{get; set;}
after that i execute update-database -verbose command in PM console.
when i execute my application it throws an error like,
"Unknown column 'Extent1.newprop' in 'field list'"
please guide me why i am getting this error does i went to the wrong way please guide me.
If your not using automatic migrations
Database.SetInitializer(new MigrateDatabaseToLatestVersion());
public class MyMigrationConfiguration : DbMigrationsConfiguration<MyDbContext>
{
public MyMigrationConfiguration()
{
AutomaticMigrationsEnabled = true; // Are you using this ?????
AutomaticMigrationDataLossAllowed = true;
}
}
Then you need to tell EF using the PM Commandlet to add another migration and update the database.
PM> Enable-Migrations //already done this ?
PM> Add-Migration myLabel
PM> Update-Database
Search for "code based migrations" on web for help
这篇关于无法将代码首次迁移到mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!