C# Azure Appservice在添加数据库迁移代码时崩溃
我正在尝试在Azure应用程序服务Web应用程序上使用code first和.NET core 我已经运行了添加迁移和更新数据库,当我在VS2017本地运行应用程序时,它会按照预期更新数据库 但当我添加以下代码尝试在我的AppService中自动运行时,应用程序崩溃,并显示错误消息“无法启动应用程序” 这是我在startup.cs中添加的一行C# Azure Appservice在添加数据库迁移代码时崩溃,c#,azure,azure-sql-database,azure-web-app-service,C#,Azure,Azure Sql Database,Azure Web App Service,我正在尝试在Azure应用程序服务Web应用程序上使用code first和.NET core 我已经运行了添加迁移和更新数据库,当我在VS2017本地运行应用程序时,它会按照预期更新数据库 但当我添加以下代码尝试在我的AppService中自动运行时,应用程序崩溃,并显示错误消息“无法启动应用程序” 这是我在startup.cs中添加的一行 using (var serviceScope = app.ApplicationServices.GetRequiredService<ISer
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
serviceScope.ServiceProvider.GetService<NWMposBackendContext>().Database.Migrate();
}
使用(var serviceScope=app.ApplicationServices.GetRequiredService().CreateScope())
{
serviceScope.ServiceProvider.GetService().Database.Migrate();
}
一旦我添加了该代码,应用程序就无法启动,如果我删除它,应用程序将按预期工作
当我将应用发布到AppServices时,是否需要添加/执行更多操作以运行迁移?设置“ASPNETCORE\u环境”:“appservice中的“Test”
立即修复了问题,否则它无法找到将DB迁移到的正确连接字符串