简体   繁体   中英

EF Core set environment not working predictably

When I go to update my database I run $env:ASPNETCORE_ENVIRONMENT="Development" first before executing the Update-Database command to set the correct environment. If I had previously deployed changes to Test for example, running this command should point me back to my Development environment and no longer be pointing at Test.

Unfortunately this only works maybe 33% of the time. Every time I run this I also run $env:ASPNETCORE_ENVIRONMENT and check that it returns back the correct environment and it does. Then I run the Update-Database command that I need and it somehow changes back to the previous environment.

Anyone have any idea on either what I am doing wrong or a way to know that I will be connected to the correct DB? This could be very bad if the wrong database is hit and data happens to get deleted or a system goes down.

Rather than exporting the variable at command line, you should set/export the variables within the database update script. So if you are running a shell script, you can export via standard export commands. If you are running perl/python, you should update the environment variables within the script. That way, you will have consistent behavior.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM