Run database migrations using Entity Framework core on application start

You can do this in the config methods in your Startup.cs. The simplest way is like this:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<ApplicationDbContext>();

    // add other services        
}

public void Configure(IApplicationBuilder app, ApplicationDbContext db)
{
    db.Database.Migrate();

    // configure other services
}

Leave a Comment