Question

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?)

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. 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?

Can I avoid running a SQL script if I want to downgrade a production database?

Thanks guys!

Was it helpful?

Solution

You could use the migrate.exe tool which comes with EF to go to specific migrations.

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

Docs can be found at: http://msdn.microsoft.com/en-us/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”
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top