Entity Framework automatic migrations do not work

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 the log object.

Can Entity Framework automatically detect and apply changes?

+4
source share
1 answer

If automatic migration is enabled, it should automatically detect any small changes in the model.

But for big changes, for example, adding a new object, I saw how to manually apply the migration, which you can do using "Add-Migration", and then run "Update-Database"

0
source

Source: https://habr.com/ru/post/1570146/


All Articles