Handle EF Core migrations with container orchestration Handle EF Core migrations with container orchestration docker docker

Handle EF Core migrations with container orchestration


I'm not sure, if this is best practice, but you can trigger schema upgrade from your C# code. You must add following code to Configure method at Startup.cs:

using (var serviceScope = app.ApplicationServices    .GetRequiredService<IServiceScopeFactory>()    .CreateScope()){    using (var context = serviceScope.ServiceProvider.GetService<EasyAdminContext>())    {        context.Database.Migrate();    }}

This way the database will be updated when the application starts