EntityFramework Core automatic migrations

asp.net-core entity-framework entity-framework-core

Question

Is there any code to perform automatic migration in Entity Framework core code first in asp.net core project?

I do it simply in MVC4/5 by adding

Database.SetInitializer(new MigrateDatabaseToLatestVersion<AppDbContext, MyProject.Migrations.Configuration>());
public Configuration() {
          AutomaticMigrationsEnabled = true;
        }

This saves time when entities changed

1
33
9/16/2016 10:41:26 AM

Accepted Answer

You can call context.Database.Migrate()in your Startup.cs

eg:

using (var context = new MyContext(...))
{
    context.Database.Migrate();
}
30
9/16/2016 8:20:51 AM

Popular Answer

EF core doesn't support automatic migrations.So you have to do it manually.

From the perspective of automatic migrations as a feature, we are not planning to implement it in EF Core as experience has showed code-base migrations to be a more manageable approach.

You can read full story here : Not to implement Automatic Migrations



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow