2

I am using asp net core 2, I can't seem to find any option or any guides on how to apply the migrations to the database on web deploy publish?

Ben Donnelly
  • 1,191
  • 5
  • 13
  • 30
  • 1
    https://stackoverflow.com/questions/35324156/automatically-execute-migrations-when-publishing-asp-net-core-app – Steve Greene Feb 27 '18 at 14:48
  • Possible duplicate of [Automatically execute migrations when publishing ASP.NET Core app](https://stackoverflow.com/questions/35324156/automatically-execute-migrations-when-publishing-asp-net-core-app) – Dmitry Pavlov Feb 27 '18 at 16:22

1 Answers1

0

This will migrate your DB on application startup.

You can call this from your Startup class:

using (var context = new MyContext(...))
{
    context.Database.Migrate();
}

EDIT

Based on the comments below:

First remember to be very careful with this because it will always run on start up no matter what which could cause issues with the database.

The answer above came from

Automatically execute migrations when publishing ASP.NET Core app

Derek Hackett
  • 190
  • 10
  • It's a copy of the link I already posted. There are other options such as generating a script that can be run or if it is Azure it can pickup the migrations. Personally, we generate migration scripts if danger is a concern. – Steve Greene Feb 27 '18 at 17:50