Enoch
Enoch

Reputation: 33

How manage migrations after publishing to Azure

I'm using a web app asp.net (.net framework) identity framework published on Azure.

I change the connectionString in the web.config file with Azure string and all works fine.

I made a simple change in a context and when I send the get request, I get this error from PostMan:

The model backing the 'MYCONTEXTNAME' context has changed since the database was created. Consider using Code First Migrations to update the database.

When I was working locally I used the commands Add-Migrations and Update-Database to update the table structure, but in Azure what do I have to do?

How I can fix this issue?

Thank you

G.

Upvotes: 0

Views: 302

Answers (2)

Sajeetharan
Sajeetharan

Reputation: 222582

You need to run those migration changes to Azure Database as well.

Take a backup of your database in Azure and Change the connection string in your code and run the migration changes

Go to Package Manager Console and

 Run - Update-Database -force

Get the script and apply to your azure db

Upvotes: 0

Yogi
Yogi

Reputation: 9749

So when there is any change in the DB schema, you need to generate migrations as usual, and then execute them on the Azure database as well.

Generally when we deploy on any environment, Azure here, we use it using scripts and use some tool for example Jenkins to automate this. And for migrations, you can use migrate.exe for executing migrations using scripts.

Otherwise you can also execute the migration from within Visual Studio also, as you would do on local environment. However it is not recommended for production instances. Just make sure that the connection string in the startup project is pointing to Azure database and the required firewall setting is configured to allow access from the machine executing the command and the database on Azure.

Upvotes: 0

Related Questions