【问题标题】:Azure Appservice crashes when adding DB Migration code添加数据库迁移代码时 Azure 应用服务崩溃
【发布时间】:2018-05-23 16:23:43
【问题描述】:

我正在尝试在 Azure 应用服务 Web 应用上首先使用代码和 .NET 核心

我已经运行了 Add-Migration 和 Update-Database,当我在 VS2017 中本地运行应用程序时,它会按预期更新数据库

但是当我添加以下代码以尝试在我的 AppService 中自动运行时,应用程序崩溃并显示错误消息无法启动应用程序

这是我添加到我的 startup.cs 中的行

 using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())
            {
               serviceScope.ServiceProvider.GetService<NWMposBackendContext>().Database.Migrate();

            }

一旦我添加了该代码,应用程序就无法启动,如果我删除它,应用程序就会按预期工作。

当我将应用发布到 AppServices 时,是否需要添加/执行更多操作才能运行迁移?

【问题讨论】:

    标签: c# azure azure-sql-database azure-web-app-service


    【解决方案1】:

    在 appservice 中设置 "ASPNETCORE_ENVIRONMENT": "Test" 立即解决了问题,否则它无法找到将数据库迁移到的正确连接字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-02
      • 2020-11-09
      • 2014-05-20
      • 1970-01-01
      • 2019-09-12
      • 2014-05-23
      • 2022-01-18
      • 2020-12-26
      相关资源
      最近更新 更多