Run database migrations using Entity Framework core on application start

后端 未结 1 1500
遥遥无期
遥遥无期 2020-12-03 22:46

Is it possible to configure StartUp.cs or project.json to run database migrations using Entity Framework Core on application start?

Now I h

相关标签:
1条回答
  • 2020-12-03 23:28

    You can do this in the config methods in your Startup.cs. The simplest way is like this:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<ApplicationDbContext>();
    
        // add other services        
    }
    
    public void Configure(IApplicationBuilder app, ApplicationDbContext db)
    {
        db.Database.Migrate();
    
        // configure other services
    }
    
    0 讨论(0)
提交回复
热议问题