我已阅读关于代码第一次迁移的每篇博文和MSDN文章(http://msdn.microsoft.com/en-us/data/jj591621.aspx),但我不清楚该如何使用它。实体框架代码第一次迁移问题 - Dataloss
这里是我的项目迁移历史:
1.Initially我用“启用的迁移”,然后添加迁移和更新数据库。 2.我部署了项目 3.我对模型做了一些小改动。重新运行添加迁移和更新数据库。 4.部署项目 5.我增加了更多的属性模式。另外,我运行禁用的迁移和运行Enable-迁移-EnableAutomaticMigration 6.现在,当我部署项目..和运行的第一次,所有现有数据已经一去不复返了
老项目的应用程序(步骤#4) - 迁移\ Configurations.cs
namespace POC_Manager.Migrations
{
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
internal sealed class Configuration : DbMigrationsConfiguration<POC_Manager.Models.POC_ManagerContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
ContextKey = "POC_Manager.Models.POC_ManagerContext";
}
protected override void Seed(POC_Manager.Models.POC_ManagerContext context)
{
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data. E.g.
//
// context.People.AddOrUpdate(
// p => p.FullName,
// new Person { FullName = "Andrew Peters" },
// new Person { FullName = "Brice Lambson" },
// new Person { FullName = "Rowan Miller" }
// );
//
}
}
}
新建项目(步骤#6) - 迁移\ Configurations.cs
namespace POC_Manager.Migrations
{
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
internal sealed class Configuration : DbMigrationsConfiguration<POC_Manager.Models.POC_ManagerContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
ContextKey = "POC_Manager.Models.POC_ManagerContext";
}
protected override void Seed(POC_Manager.Models.POC_ManagerContext context)
{
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data. E.g.
//
// context.People.AddOrUpdate(
// p => p.FullName,
// new Person { FullName = "Andrew Peters" },
// new Person { FullName = "Brice Lambson" },
// new Person { FullName = "Rowan Miller" }
// );
//
}
}
}
老项目(步骤#4) - 从GET-迁移输出
PM>获取的迁移 已应用到目标数据库检索迁移。 201405271907443_AutomaticMigration 201404252210039_InitialCreate PM>
新建项目(步骤#6) - 从获取的迁移输出
PM>获取的迁移 已经应用到目标数据库中检索迁移。 201407022020263_AutomaticMigration 201406262227296_AutomaticMigration 201405271907443_AutomaticMigration 201404252210039_InitialCreate PM>
另一个令人困惑的是,...我仍然需要运行启用自动迁移后更新的数据库的命令?