Last active
November 8, 2019 05:23
-
-
Save eduuh/f57ec67049c57c99d7611a373e87f5de to your computer and use it in GitHub Desktop.
Migrate the database automatically to the latest Migrations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void Main(string[] args) | |
{ | |
var host = CreateWebHostBuilder(args).Build(); | |
using (var scope = host.Services.CreateScope()) | |
{ | |
var Services = scope.ServiceProvider; | |
try | |
{ | |
var context = Services.GetRequiredService<DataContext>(); | |
context.Database.Migrate(); | |
// Seed your database here to | |
// Seed.SeedData(context); | |
} | |
catch (Exception ex) | |
{ | |
var logger = Services.GetRequiredService<ILogger<Program>>(); | |
logger.LogError(ex, "An error occured during migration."); | |
} | |
} | |
host.Run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment