HELP! I have an MVC4 app hosted on Azure. I'm using EF code-first. Here's my scenario:
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.
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
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.
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"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With