dotnet ef does not respect configuration

asp.net-core c# entity-framework-core

Question

I have two configurations: - Development - Production

with following json settings files: - appsettings.Production.json - appsettings.Development.json

In each settings file I have following sections:

(production)

"Sql" : {
    "Name": "App_Prod",
    "Server": "127.0.0.1",
    "Port": 0,
    "Database": "db_prod",
    "Username": "user_prod",
    "Password": "secret"
   },

(development)

"Sql" : {
    "Name": "App_Dev",
    "Server": "127.0.0.1",
    "Port": 0,
    "Database": "db_dev",
    "Username": "user_dev",
    "Password": "secret"
   },

I'm injectings these into my DbContext constructor, and it works properly. I updated my database using migrations system using foolowing command:

dotnet ef database update --context MyDbContext--configuration Development

it worked, and my database scheme has been updated.

But when I'm trying to update my production database using following commanad:

dotnet ef database update --context MyDbContext--configuration Production

it gaves me information that any migrations no needs to be applied.

I dumped connection string in MyDbContext, and I can see that the DbContext still use Development configuration even I type that it should be use Production settings file.

Why migration mechanism does not respect my configuration? How I can run dotnet ef with appsettings.Production?

1
0
10/5/2018 11:52:05 AM

Accepted Answer

In my case(Linux environment) using:

export ASPNETCORE_ENVVIRONMENT=Development

changes environment used by database update command

0
11/5/2018 8:36:31 AM

Popular Answer

--configuration is for build configuration (e.g. Release, Debug)

Pre-v2.0:

Use -e or --environment:

PM> dotnet ef database update --context MyDbContext -e Production

v2.0+:

Set ASPNETCORE_ENVIRONMENT environment variable before executing command:

PM> $env:ASPNETCORE_ENVIRONMENT='Production'



Related Questions





Related

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