3

Im trying to remove a migration that went wrong. I have the following migrations: InitialMigration MyBadMigration

First my database state is at InitialMigration.

  • I then run "dotnet ef migrations add MyBadMigration"
  • I then run my application which updates the database with dbContext.Database.Migrate();
  • My database is updated to the new state.
  • I then realize that my migration is bad and I want to revert the changes.
  • I apply "dotnet ef database update InitialMigration" and I can see that my database is reverted.
  • I then want the snapshot and MyBadMigration.cs to be reverted so
  • I apply "dotnet ef migrations remove"
  • The database is then updated to MyBadMigration once more and I cant remove the migration.

If I use "dotnet ef migrations remove -f" when in InitialMigration the sourcefiles is updated (snapshot is reverted and MyBadMigration.cs is deleted) bu the database is still in the new state.

I use .net core 2.0 and ef core 2.0

forsmyr
  • 304
  • 3
  • 14
  • 1
    Follow this guide carefully https://learn.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/ Especially updates to Program.Main method. dotnet ef builds your service provider to initialize your context but your code while building service provider is calling Migrate(), which is incorrect design. – Smit Nov 16 '17 at 23:38
  • This was the answer to my question https://stackoverflow.com/questions/45941707/why-remove-migration-run-my-app – forsmyr Nov 17 '17 at 12:00

0 Answers0