Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
moraleslos opened this issue Aug 31, 2017 · 8 comments
Labels
closed-no-further-action The issue is closed and no further action is planned.

Comments

@moraleslos
Copy link

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
Copy link
Author

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?

@bricelam
Copy link
Contributor

bricelam commented Sep 1, 2017

See #8328 for context

@ajcvickers ajcvickers added the closed-no-further-action The issue is closed and no further action is planned. label Sep 5, 2017
@hung-doan
Copy link

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

I tried, but still not work :(

@ExcaliburVT
Copy link

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.

@theBoringCoder
Copy link

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

@Ice2burn
Copy link

Ice2burn commented Jun 13, 2018

Issue still occurs. appsettings.Development.json ignored.

@tonyferreira
Copy link

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 ...

@ckpearson
Copy link

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.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned.
Projects
None yet
Development

No branches or pull requests

9 participants