我使用实体框架创建代码优先模型,在将第一个版本安装到客户端后,我们发现数据库列发生了一些变化,我使用了Entity Framework的迁移,并且您应用了所有迁移步骤,因此客户端的数据库不存在迁移历史记录的行。最后更改,并在执行时显示此消息
Table 'nameTable' already exists
或者
Additional information: Duplicate column name 'Reference'
该类配置代码
internal sealed class Configuration : DbMigrationsConfiguration<GSM.DataAccess.GSMContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = false;
SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
}
protected override void Seed(GSM.DataAccess.GSMContext context)
{
}
}
以及此类首次迁移的代码
public partial class AddMoreInformationColumn : DbMigration
{
public override void Up()
{
AddColumn("dbo.People", "Reference", c => c.String(unicode: false));
AddColumn("dbo.Products", "Reference", c => c.String(unicode: false));
AddColumn("dbo.Products", "SalePrice", c => c.String(unicode: false));
AddColumn("dbo.Products", "WholePrice", c => c.String(unicode: false));
}
public override void Down()
{
DropColumn("dbo.People", "Address");
DropColumn("dbo.People", "Reference");
DropColumn("dbo.Products", "Reference");
DropColumn("dbo.Products", "SalePrice");
DropColumn("dbo.Products", "WholePrice");
}
}
对于当前问题,客户端迁移快照似乎不同步。您可以在Up()方法中注释掉冲突的代码,然后执行更新数据库以使它们恢复同步。如果您担心缺少更改,则需要使用架构比较工具(http://www.techbubbles.com/sql-server/schema-compare-for-sql-server-in-visual-studio-2013/)。
我会重新考虑您的更新客户端(PRODUCTION)数据库的策略。我们要做的是从客户端站点上运行的迁移中生成脚本,以对其进行更新。请参阅:http : //cpratt.co/migrating-production-database-with-entity-framework-code-first/#at_pco=smlwn-1.0&at_si=54ad5c7b61c48943&at_ab=per-12&at_pos=0&at_tot=1
您还必须考虑数据库初始化程序是什么,并将其设置为null或migrationtolatestversion进行部署。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句