Sourabh Dhiman

Sourabh Dhiman

  • 1.3k
  • 446
  • 10.5k

Run automatic migration in .net core using ef

Jun 18 2024 11:40 AM

Hello everyone Please help me, I have added a new field in our model, Now I want to run our API project so it updates automatic fields in our database. But in my case no updated fields in our database. This is my code

public static class MigrationsConfiguration
{
    public static IApplicationBuilder DbMigrations(this IApplicationBuilder app)
    {
        using var scope = app.ApplicationServices.CreateScope();
        var logger = scope.ServiceProvider.GetRequiredService<ILogger<MyFile>>();
        var db = scope.ServiceProvider.GetRequiredService<dbcontext>();

        logger.LogInformation("Starting migrations");

        db.Database.Migrate();

        logger.LogInformation("Db migrations completed");

        return app;
    }
}

 


Answers (3)