efcore icon indicating copy to clipboard operation
efcore copied to clipboard

EF Core 2.0 Update-Database Powershell command doesn't recognize Environment parameter

Open moraleslos opened this issue 9 years ago • 8 comments

Got my ASP.NET Core 2.0 + EF Core 2.0 project up and running locally. Now when I'm trying to set up my production database using the powershell update-database command like this:

Update-Database -context MyDbContext -Environment Production

targeting my production environment, the command fails and says it doesn't recognize the 'Environment' parameter:

Update-Database : A parameter cannot be found that matches parameter name 'Environment'.

Seems like this parameter is missing entirely. Is there a different way to run the update-database command to target a particular environment based on appsettings.{environment}.json?

moraleslos avatar Aug 31 '17 20:08 moraleslos

Looks like you need to explicitly set the environment in powershell before running the update-database command. In my case, this worked for me:

$env:ASPNETCORE_ENVIRONMENT='Production' Update-Database -context MyDbContext

I don't know why this was changed-- preferred the older way with the -Environment argument so that it's only one command needed to run. Can the -Environment argument be added back to update / drop database commands?

moraleslos avatar Sep 01 '17 14:09 moraleslos

See #8328 for context

bricelam avatar Sep 01 '17 18:09 bricelam

$env:ASPNETCORE_ENVIRONMENT='Production' Update-Database -context MyDbContext

I tried, but still not work :(

hung-doan avatar Nov 23 '17 09:11 hung-doan

I am encountering this as well. We purposefully have the root appsettings.json have a token for the connectionstring so that it can be replaced by the deployment script and have the appsettings.Development.json override the setting for the developer workstations. The Update-Database command seems to totally ignore environment and only use the root appsettings.json.

ExcaliburVT avatar Nov 30 '17 19:11 ExcaliburVT

Bring back the -e switch. Removing functionality that we relied on makes no sense.

theBoringCoder avatar May 21 '18 18:05 theBoringCoder

Issue still occurs. appsettings.Development.json ignored.

Ice2burn avatar Jun 13 '18 15:06 Ice2burn

Just wrestled with this on a Windows server running TeamCity hosting multiple builds across multiple environments (development, staging, etc). The following build step didn't work:

set ASPNETCORE_ENVIRONMENT=staging && dotnet ef database update ...

In order to properly set the environment, it was necessary to put each command on a new line:

set ASPNETCORE_ENVIRONMENT=staging dotnet ef database update ...

tonyferreira avatar Jun 15 '18 01:06 tonyferreira

I've also just run into this issue, it took using -verbose to track down what was going on, good job there weren't any migrations to be run on one of our environments!

Our issue is that we're using Development for something other than local dev.

The startup project is configured correctly, and has the correct environment set in the debug properties, but EF core via powershell isn't honouring this, and is instead just assuming development.

Can we get it honouring this if it's set against the startup project? It's a bit of a pain having to set the environment variable in the powershell host.

ckpearson avatar Jul 04 '18 22:07 ckpearson