在Azure上为通过GitHub部署的dotnet核心站点运行迁移 [英] Run migrations on azure for dotnet core site deployed with GitHub
问题描述
我有一个使用.Net核心构建的小型网站,其中包括SQLite数据库和实体框架核心.我在Mac上使用VS Code.
I have a small website built with .Net core that includes a SQLite database and entity framework core. I'm using VS Code and on a mac.
在本地管理数据库很容易-dotnet ef database update
效果很好.问题是在部署到Azure时正在运行迁移.
It is easy to manage the database locally - dotnet ef database update
works great. The problem is running migrations when deploying to Azure.
我的存储库位于GitHub上,当我推送到master分支时,我将Azure配置为从GitHub提取代码.部署工作正常,但迁移未在Azure上运行.
My repo is on GitHub, and I configured Azure to pull code from GitHub when I push to the master branch. The deploy is working fine, but migrations aren't running on Azure.
我在Startup.cs中看到了一些可以使用yourDbContext.Database.Migrate()
的建议,但是.Migrate()
似乎不再可用.
I've seen some suggestions that I can use yourDbContext.Database.Migrate()
in Startup.cs, however it appears that .Migrate()
is no longer available.
我尝试从Azure中下载部署脚本并通过将call :ExecuteCmd dotnet ef database update -e Production
添加到deploy.cmd中对其进行自定义,但这似乎不起作用.
I've tried downloading the deployment script from Azure and customizing it by adding call :ExecuteCmd dotnet ef database update -e Production
to deploy.cmd, but that doesn't appear to be working.
我尝试使用PS外壳程序,可以通过Kudu站点访问它以手动运行迁移,但是当尝试运行dotnet ef database update
时,结果是No executable found matching command "dotnet-ef"
I've tried using the PS shell I can access through the Kudu site to manually run migrations, but when trying to run dotnet ef database update
the result is, No executable found matching command "dotnet-ef"
这里有一个非常类似的问题( EF核心(1.0.0)在Azure App Services上迁移),但该问题没有任何答案.
There is a very similar question here (EF Core (1.0.0) Migrations On Azure App Services), but that question did not get any answers.
推荐答案
在代码中初始化数据库时,可以运行context.Database.Migrate()
.迁移将在您首次启动应用程序时运行
You can run context.Database.Migrate()
when you initialize the database in your code. The migrations will run when you first launch your application
这篇关于在Azure上为通过GitHub部署的dotnet核心站点运行迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!