Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ef core doesn't use ASPNETCORE_ENVIRONMENT during update-database

I use visual studio to update all my environments with a certain migration. It had worked fine using the command below.

update-database -Migration initMigrationProduct -c ProductContext -Environment Production 

In ef core 2.0 this command has been changed and parameter -Environment has been removed. In the docs it said.

"With 2.0, you can use the ASPNETCORE_ENVIRONMENT environment variable instead."

https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet

I have now tried all kinds of ways but when I run the update-database with ef core 2.0 it doesn't use the ASPNETCORE_ENVIRONMENT variable. I tried to set in registry, application properties.

Please let me know what I need to do to get this working to update different environments?

If I start the application with different launchsettings it works but not using the package manager console.

like image 402
joakimja Avatar asked Aug 25 '17 12:08

joakimja


People also ask

How do I update my EF core model after database change?

Right-click anywhere on the design surface, and select Update Model from Database... In the Update Wizard, select the Refresh tab and select your table then click Finish button.

How do I update my EF database?

Let's use Update-Database to apply this migration to the database. Run the Update-Database command in a Package Manager console. Code First Migrations will compare the migrations in our Migrations folder with the ones that have been applied to the database.

How is Aspnetcore_environment used?

ASP.NET Core uses an environment variable called ASPNETCORE_ENVIRONMENT to indicate the runtime environment. The value of this variable can be anything as per your need but typically it can be Development, Staging, or Production. The value is case insensitive in Windows and Mac OS but it is case sensitive on Linux.


1 Answers

To set the ASPNETCORE_ENVIRONMENT variable in Package Manager Console (PMC) , inside visual studio, to Production use this command first

$env:ASPNETCORE_ENVIRONMENT='Production' 

Then you can use

Update-Database 

normally.

like image 106
Martin Florin Avatar answered Sep 28 '22 06:09

Martin Florin