【问题标题】:Run migrations on azure for dotnet core site deployed with GitHub在 azure 上为使用 GitHub 部署的 dotnet 核心站点运行迁移
【发布时间】:2017-03-03 19:59:38
【问题描述】:

我有一个使用 .Net 核心构建的小型网站,其中包括 SQLite 数据库和实体框架核心。我正在使用 VS Code 并在 Mac 上。

在本地管理数据库很容易 - dotnet ef database update 效果很好。问题是在部署到 Azure 时运行迁移。

我的存储库在 GitHub 上,我将 Azure 配置为在推送到主分支时从 GitHub 提取代码。部署工作正常,但迁移未在 Azure 上运行。

我在 Startup.cs 中看到了一些可以使用 yourDbContext.Database.Migrate() 的建议,但似乎 .Migrate() 不再可用。

我尝试从 Azure 下载部署脚本并通过将 call :ExecuteCmd dotnet ef database update -e Production 添加到 deploy.cmd 来自定义它,但这似乎不起作用。

我尝试使用可以通过 Kudu 站点访问的 PS shell 手动运行迁移,但是当尝试运行 dotnet ef database update 时,结果是 No executable found matching command "dotnet-ef"

这里有一个非常相似的问题 (EF Core (1.0.0) Migrations On Azure App Services),但该问题没有得到任何答案。

【问题讨论】:

    标签: azure asp.net-core entity-framework-core


    【解决方案1】:

    您可以在代码中初始化数据库时运行context.Database.Migrate()。迁移将在您首次启动应用程序时运行

    【讨论】:

    • 谢谢@matthijsb - 我在几个地方看到过这个答案,但它对我不起作用。我再次尝试并让它工作。诀窍是我需要将using Microsoft.EntityFrameworkCore; 添加到 Startup.cs 的顶部。没有它,我仍然能够在找到 .Database 的 VS Code 中创建上下文和智能感知。但是直到添加了额外的using 才找到.Migrate()。
    • 在此链接stackoverflow.com/questions/42624340/…找到解决方案
    猜你喜欢
    • 1970-01-01
    • 2020-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-17
    • 1970-01-01
    相关资源
    最近更新 更多