EF迁移无法删除迁移 [英] EF Migrations not able to remove migration
问题描述
编辑:我删除了数据库. 它仍然告诉我迁移已应用.我不买你的狗屎,EF ...
I dropped the database. It still tells me the migration is applied. I don't buy your shit, EF...
我有5个迁移,但第5个是偶然创建的.它不包含任何更改(Up
和Down
方法为空).我不假思索地将其应用于数据库.
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.
现在,当我运行dotnet ef database update migration4
时,它告诉我它成功还原了迁移#5,并且表__EFMigrationsHistory
没有显示迁移#5的条目.尝试使用dotnet ef migrations remove
删除它时,它告诉我迁移#5仍适用于数据库,并且__EFMigrationsHistory
中的条目显示为备份.
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.
使用dotnet ef database update migration3
回滚到迁移#3时,它确实从迁移#4中删除了更改,并从__EFMigrationsHistory
表中删除了条目.
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.
有什么建议吗?我不知道从哪里开始.我是否需要重做整个数据库和/或迁移?我尝试覆盖优先迁移#5,但dotnet ef migrations add
不接受参数-f
或--force
.
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
.
推荐答案
更好的方法是 转到
PM删除迁移
PM Drop-DataBase
PM Drop-DataBase
或在解决方案中删除您的迁移文件夹探索并创建新的迁移 这将使您的全部5次迁移变成一次迁移
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添加迁移
PM更新数据库
这篇关于EF迁移无法删除迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!