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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With