1

In my ASP.NET Core application, I have two application settings, one for production and one for development. I'm also using database migrations to manage my database, that said, with their being two connection strings I can only update the development database from Visual Studio. My question is, is it possile to run database migrations against two connections strings? i.e. the connections strings I have stored in appsettings.Production.json and appsettings.Development.json?

appsettings.Development.json

{     
  "ConnectionStrings": {
    "DevConnection": "Server=tcp:devdatabase.database.windows.net,1433;Initial Catalog=MyDevelopment;Persist Security Info=False;User ID=whatever;Password=whatever;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
  },
  "AllowedHosts": "*"
}

appsettings.Production.json

{     
  "ConnectionStrings": {
    "ProdConnection": "Server=tcp:proddatabase.database.windows.net,1433;Initial Catalog=MyProduction;Persist Security Info=False;User ID=whatever;Password=whatever;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
  },
  "AllowedHosts": "*"
}

Both my database are stored in Azure, typically if I'm wanting to make changes I'll create a migration in the following manner:

Add-Migration AddedBoolColumns

Followed by

Update-Database

The migration takes the development connection string and updates the development database but production remains unchanged and sometimes I want those changed to carry to that database as well. Is there a way this can be done?

2
  • it would defeat the purpose to update both databases at the same time. the purpose of a development db would be to test it and then update the production db if all is ok Commented Jun 3, 2021 at 11:04
  • Does this answer your question: stackoverflow.com/a/66950778/5519026 Commented Jun 3, 2021 at 11:35

1 Answer 1

0

If you want to run the migrations from your local machine you can add the connection string to Update-Database as an argument. Example Below.

Update-Database -Connection your_connection_string

With that said you can run the migrations to as many databases as you want ^^

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.