remove-migration doesn’t remove the migration files

Using .net core and Entity Framework I encountered the problem that since introducing a seeding migration, the add-migration and remove-migration commands no longer worked as expedted.

Problem 1: add-migration would try to update a table with every new migration – even though the data didn’t change.

Problem 2: remove-migration no longer removed the migration.cs files. There was no error message, the .cs files just remained and the migration was never removed.

The solution for both problems was within the table (the one which add-migration was trying to update every time). In Context.cs it had a default value. I cannot say if defaultValues are a problem in general or not, but it looked like this:

modelBuilder.Entity<Profession>(entity =>
    entity.Property(e => e.Name)

After removing the HasDefaultValueSql part, the migration scripts went back to working as intended.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.