Skip to content

Instantly share code, notes, and snippets.

@eduuh
Last active November 8, 2019 05:23
Show Gist options
  • Save eduuh/f57ec67049c57c99d7611a373e87f5de to your computer and use it in GitHub Desktop.
Save eduuh/f57ec67049c57c99d7611a373e87f5de to your computer and use it in GitHub Desktop.
Migrate the database automatically to the latest Migrations
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