Net Core 2 - Entity Framework: Update-Database of different environment ef-migrations entity-framework-6



  • net core 2.0 initiative
  • entity framework (code first)
  • various appsettings multiple environments' json files

    My database scripts are created using the Package Manager Console (Add-Migration, Update-Database)

When I execute PM>"Get-DbContext," it retrieves data from my appsettings. GREAT, that's what I want most of the time using the development.json file!

But how do I instruct it to get database variables from appsettings? Instead of development, should PM commands use staging.json?

I've tried making fresh launchSettings.json profiles and setting "ASPNETCORE ENVIRONMENT" to "Staging," but no one appears to take it into consideration except PM.

I can get around that by using Script-Migration to produce scripts, but I like the quick ups and downs I receive and won't utilise that method to deploy to production.

2/21/2018 7:28:18 PM

Accepted Answer

The ASPNETCORE ENVIRONMENT may be manually updated by performing this command in the Package Manager Console, albeit it is not extensively documented.


then you can use the following command to make sure it is referring to the database you want:

PM> Get-DbContext

This will remove

providerName                            databaseName          dataSource                                 options
------------                            ------------          ----------                                 -------
Microsoft.EntityFrameworkCore.SqlServer myDatabase  ,1433           None

then just execute your instructions as usual. Example:


Commands mentioned:

3/2/2018 10:05:48 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow