Entity Framework automatic migrations enabled does not work

automatic-migration c# ef-migrations entity-framework

Question

I have this db configuration

public class AppDbContext : DbContext 
    {

         public AppDbContext(string connectionStringOrName)
            : base(connectionStringOrName)
        {
            Database.SetInitializer(new AppDbInitializer());
        }

         public AppDbContext()
             : this("name=AppDbContext")
        {

        }

         public DbSet<User> Users { get; set; }
         public DbSet<Log> Logs { get; set; }
    }

and I have this migration configuration

public class AppDbInitializer : MigrateDatabaseToLatestVersion<AppDbContext,AppDbMigrationConfiguration>
{
}


  public class AppDbMigrationConfiguration : DbMigrationsConfiguration<AppDbContext>
    { 
        public AppDbMigrationConfiguration()
        {
            AutomaticMigrationsEnabled = true;
            AutomaticMigrationDataLossAllowed = true;
        }

        protected override void Seed(AppDbContext context)
        {
            if (context.Users.Any()) return;

            AddAdmin(context, "Admin", "admin@test.com");
        }
   }

And I added another field to Log entity.

Can Entity Framework automatically detect and apply changes?

1
4
4/7/2016 4:25:48 PM

Popular Answer

If Automatic Migrations are enabled, it should auto detect any small changes in the model.

But for larger changes, eg addition of new entity, I have seen to manually apply migration, which you can do with "Add-Migration" and then running "Update-Database"

0
1/20/2016 5:04:03 AM


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