How to run EF Core migrations on SQL Server database using Docker? How to run EF Core migrations on SQL Server database using Docker? docker docker

How to run EF Core migrations on SQL Server database using Docker?


You need to add below lines in Confiure of startup file. It will executed when the application is started. It will update all the migration files to database.

using (IServiceScope scope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())            {                scope.ServiceProvider.GetService<MyDBCOntext>().Database.Migrate();            }

This worked for me.