Dan*_*tos 2 .net azure ef-code-first dotnet-cli
我刚刚将一个应用程序部署到一个 azure 应用服务中。我的项目确实有要应用的迁移。但是我无法通过使用 azure app 命令行来应用它们
dotnet ef 数据库更新
D:\home\site\wwwroot> 找不到匹配命令“dotnet-ef”的可执行文件
我如何远程应用它们?
For dotnet-ef, I assumed that you are talking about Entity Framework Core. I have tried to run dotnet ef database update under D:\home\site\wwwroot of KUDU and Package Manager Console of VS, I could encounter the same issue as you mentioned.
I found a similar issue No executable found matching command "dotnet-ef":
DotNet CLI can only resolve "dotnet-ef" when it is within the project directory.
I could run the commands dotnet ef migrations add, dotnet ef database update via Powershell. For detailed command usage, you could follow EF Core .NET Command-line Tools.
How to apply database code first migrations in an azure deployed application?
Per my understanding, you could not do that. You may need to manually run update-database as vivek nuna answered under Package Manager Console of VS, or you could use Powershell and cd to your project directory, and execute dotnet ef database update to apply any pending migrations for your context to the database, then deploy your application to azure web app.
此外,EF 不支持自动迁移,您可能需要手动执行Add-Migration或dotnet ef migrations add添加迁移文件。您可以显式执行命令来应用迁移,也可以在代码中应用迁移。您可以在文件的Configure方法中添加以下代码Startup.cs:
using (var scope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
{
scope.ServiceProvider.GetRequiredService<ApplicationDbContext>().Database.Migrate();
}
Run Code Online (Sandbox Code Playgroud)
此外,您也可以关注这个类似的问题。
| 归档时间: |
|
| 查看次数: |
5526 次 |
| 最近记录: |