简体   繁体   English

EF 4.3.1迁移-如何降级生产数据库?

[英]EF 4.3.1 Migration - how to downgrade a production database?

I have been looking at how to produce a downgrade in EF 4.3.1 Migrations, and all I have found is only about scripting (like this EF 4.3 Migration - how to produce a downgrade script? ) 我一直在研究如何在EF 4.3.1迁移中产生降级,而我发现的只是关于脚本编写(例如EF 4.3迁移-如何产生降级脚本?

To upgrade my user's production database I call the method MigrateDatabaseToLatestVersion<TContext, TMigrationsConfiguration> upon application startup, so I make sure that all users have the same database schema after they install a new version of my app. 要升级用户的生产数据库,我在应用程序启动时调用方法MigrateDatabaseToLatestVersion<TContext, TMigrationsConfiguration> ,因此,请确保所有用户在安装新版本的应用程序后都具有相同的数据库架构。 I don't need to run any scripts on the client side once the migrations are configured. 配置迁移后,无需在客户端上运行任何脚本。

What happens if I want to downgrade to a different version? 如果我想降级到其他版本会怎样? It seems quite obvious that this method only moves Up until it reaches the latest migration... is there something like MigrateDatabaseToVersion<TContext, TMigrationsConfiguration, DbMigration> where the DbMigration object is the target migration? 似乎很明显,此方法只会向上移动直到到达最新的迁移为止……是否有MigrateDatabaseToVersion<TContext, TMigrationsConfiguration, DbMigration>之类的MigrateDatabaseToVersion<TContext, TMigrationsConfiguration, DbMigration>其中DbMigration对象是目标迁移?

Can I avoid running a SQL script if I want to downgrade a production database? 如果要降级生产数据库,是否可以避免运行SQL脚本?

Thanks guys! 多谢你们!

You could use the migrate.exe tool which comes with EF to go to specific migrations. 您可以使用EF附带的migration.exe工具进行特定的迁移。

Migrate.exe MyApp.exe /startupConfigurationFile=”MyApp.exe.config” /targetMigration=”myTargetMigration”

Docs can be found at: http://msdn.microsoft.com/en-us/data/jj618307.aspx 可以在以下位置找到文档: http : //msdn.microsoft.com/zh-cn/data/jj618307.aspx

Edit: How to use a connection string 编辑:如何使用连接字符串

Migrate.exe whereYourMigrationsAre.dll /connectionString=”Data Source=localhost;Initial Catalog=blah;whatever else you want to set” /connectionProviderName=”System.Data.SqlClient”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM