从代码自动迁移中的C#自定义迁移?
我在启动应用程序时运行所有迁移,如下所示:从代码自动迁移中的C#自定义迁移?,c#,entity-framework,C#,Entity Framework,我在启动应用程序时运行所有迁移,如下所示: var configuration = new DbMigrationsConfiguration<MyContext> { TargetDatabase = new DbConnectionInfo("DataBase"), AutomaticMigrationsEnabled = true, A
var configuration = new DbMigrationsConfiguration<MyContext>
{
TargetDatabase = new DbConnectionInfo("DataBase"),
AutomaticMigrationsEnabled = true,
AutomaticMigrationDataLossAllowed = true
};
_migrator = new DbMigrator(configuration);
_migrator.Update();
我怎样才能完成这项任务?我试图在配置中设置迁移目录,但没有成功(没有发生任何情况,迁移未受影响)。为什么不能通过package manager控制台使用内置的迁移管理
enable-migrations (make sure you have the right project selected - creates a
migrations directory)
add-migration MyFirstMigration
update-database
每次在上下文中更改数据库集中的模型后,都需要手动执行此操作。但通过这种方式,它会为您生成所有迁移Sql,并使用种子方法创建一个配置类,您可以在运行时使用该方法更新新架构:
update-database
enable-migrations (make sure you have the right project selected - creates a
migrations directory)
add-migration MyFirstMigration
update-database
update-database