10

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.

It is easy to manage the database locally - dotnet ef database update works great. The problem is running migrations when deploying to 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.

I've seen some suggestions that I can use yourDbContext.Database.Migrate() in Startup.cs, however it appears that .Migrate() is no longer available.

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.

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"

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.

Community
  • 1
  • 1
Dingels35
  • 285
  • 2
  • 4
  • 10

1 Answers1

9

You can run context.Database.Migrate() when you initialize the database in your code. The migrations will run when you first launch your application

matthijsb
  • 909
  • 5
  • 12
  • 2
    Thanks @matthijsb - I had seen this answer in a few places and it wasn't working for me. I tried it again and got it to work. The trick was I needed to add `using Microsoft.EntityFrameworkCore;` to the top of Startup.cs. Without it I was still able to create the context and intellisense in VS Code found `.Database`. But it didn't find `.Migrate()` until the additional `using` was added. – Dingels35 Oct 23 '16 at 00:49
  • Found an solution in this link https://stackoverflow.com/questions/42624340/deploying-asp-net-core-web-app-sql-from-a-repository – Jo Paul Jan 22 '19 at 22:24