EF Migrations not able to remove migration

♀尐吖头ヾ 提交于 2020-08-05 06:02:12

问题


Edit: I dropped the database. It still tells me the migration is applied. I don't buy your shit, EF...

I have 5 migrations, but the 5th has been created on accident. It doesn't hold any changes (Up and Down methods are empty). Without thinking I appied it to the database.

Now when I run dotnet ef database update migration4 it tells me it successfully reverted migration #5 and the table __EFMigrationsHistory doesn't show an entry for migration #5. Upon trying to remove it with dotnet ef migrations remove it tells me that migration #5 is still applied to the database and the entry in __EFMigrationsHistory shows back up.

When rolling back to migration #3 with dotnet ef database update migration3 it does remove the changes from migration #4, and removes the entries from the __EFMigrationsHistory table.

Now, when trying to remove, it just reapplies all the migrations. Same for reverting back to initial migration.

Any suggestions? I have no idea where to begin. Do I have to redo the whole database and/or migrations? I tried overriding migration #5 but dotnet ef migrations add doesn't accept the parameters -f or --force.


回答1:


the better way is go to

PM Remove-Migration

PM Drop-DataBase

or delete your migration folder in your solution explore and create a new migration this will make your all 5 migration into one migration

PM Add-Migration

PM Update-Database



来源:https://stackoverflow.com/questions/51892239/ef-migrations-not-able-to-remove-migration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!