CallumVass
CallumVass

Reputation: 11458

Entity Framework Migrations

In my web.config, I have a connection string set which is different in my web.release.config where it is changed to use our production database using an xdt:transform. The problem is, I have only been running add-migration and update-database on the database contained within web.config. Is there some way I can run update-database when I publish using the release configuration?

To get around this in the short term, I change the connection string contained within web.config to the one contained in web.release.config and then run update-database prior to publishing, but this defeats the purpose of using an xdt:transform?

Upvotes: 0

Views: 225

Answers (1)

tne
tne

Reputation: 7261

If you're using the VS Publish Web tool, you can check "Execute Code First Migrations (runs on application start)" in Settings.

If you're deploying to Azure, they can also run migrations on their side, I believe (I remember reading about "new" Azure-specific things regarding this just a couple of months ago, definitely less than a year).

Otherwise, you can always pass arguments to Update-Database to target another database (ConnectionStringName, ConnectionString, ConnectionProviderName), you shouldn't have to fiddle with the Web.config file.

Upvotes: 1

Related Questions