Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to roll back EF migration on Azure

HELP! I have an MVC4 app hosted on Azure. I'm using EF code-first. Here's my scenario:

  1. I set a flag in my production database to cause the website to display a "website is disabled" message in lieu of the usual website behavior.

  2. I published an update to the website code to the Staging instance. When I ran the staging instance, it applied some migrations to the database schema. At this point, the production instance would not work if I were to re-enable it because the database schema is not compatible with the production code

  3. When I tested the staging instance, I discovered that it doesn't work correctly.

Now I realize that I don't know how to back out the EF migrations that I applied so that I can re-enable the Production instance and get back to where I was before I ran the Staging instance. I know how to use the Package Manager Console in Visual Studio to go to a specific migration in the local database, but I have no idea how to manually tell Azure to update-database to a specific migration.

like image 329
Bob.at.Indigo.Health Avatar asked Nov 18 '13 08:11

Bob.at.Indigo.Health


2 Answers

Navigate to your database's dashboard on the Azure portal and select "Show connection strings". Copy the ADO.NET string into the -ConnectionString switch of the Update-Database command. You should end up with something like this:

Update-Database 
-TargetMigration {YourMigration} 
-ConnectionString "Server=tcp:{your server name}.database.windows.net,1433;
                   Database={your db};
                   User ID={your user}@{your server};
                   Password={your password};
                   Trusted_Connection=False;
                   Encrypt=True;
                   Connection Timeout=30;" 
-ConnectionProviderName "System.Data.SqlClient"
like image 111
Colin Avatar answered Oct 06 '22 00:10

Colin


Run a "Get-Migrations"

it will display a list of migrations.

After that:

Update-Database -TargetMigration:"{NAME_OF_SELECTED_MIGRATION}"

where {NAME_OF_SELECTED_MIGRATION} will be replaced with the name you want. PS: remove "{" and "}" characters.

like image 25
Thiago Custodio Avatar answered Oct 05 '22 23:10

Thiago Custodio