简体   繁体   English

EF Core 设置环境无法按预期工作

[英]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.当我 go 更新我的数据库时,我首先运行$env:ASPNETCORE_ENVIRONMENT="Development"然后执行Update-Database命令以设置正确的环境。 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.例如,如果我之前部署了对 Test 的更改,则运行此命令应该将我指向我的开发环境,而不再指向 Test。

Unfortunately this only works maybe 33% of the time.不幸的是,这只适用于 33% 的时间。 Every time I run this I also run $env:ASPNETCORE_ENVIRONMENT and check that it returns back the correct environment and it does.每次我运行它时,我也会运行$env:ASPNETCORE_ENVIRONMENT并检查它是否返回正确的环境并且确实如此。 Then I run the Update-Database command that I need and it somehow changes back to the previous environment.然后我运行我需要的Update-Database命令,它会以某种方式变回以前的环境。

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.因此,如果您正在运行 shell 脚本,您可以通过标准导出命令进行导出。 If you are running perl/python, you should update the environment variables within the script.如果您正在运行 perl/python,则应更新脚本中的环境变量。 That way, you will have consistent behavior.这样,您将有一致的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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