Legion Developers

Sharing Knowledge

Execute ef-core migrations with different settings

EF Core

Hi guys, now I want to share how to execute ef-core migrations with different appsettings.json files, to change the string connection to execute migrations according to the environment.

Supposing that you have different string connections for each environment that you have, for example: development, staging, production; you could have three appsettings.

  1. appsettings.development.json
  2. appsettings.staging.json
  3. appsettings.production.json

If you want to execute migrations with each connection string declared in those files, you need to execute the following command in package manager console.

$env:ASPNETCORE_ENVIRONMENT='Production'
Package manager console command
Package manager console command

and then you could call Update-Database to execute migrations with the associated environment.

I hope that post could help you. Don’t forget to check my previous post

Execute ef-core migrations with different settings

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top