How do I undo the last Add-Migration command?

匿名 (未验证) 提交于 2019-12-03 01:58:03

问题:

I have created a migration using the Add-Migration command, but I'd like to change the name of that migration. How can I undo the migration command, so that I can regenerate it using the new desired name?

Is it just a matter of deleting the generated files, or this could be a bad idea?

回答1:

If you haven't used Update-Database you can just delete it. If you've run the update then roll it back using Update-Database -TargetMigration "NameOfPreviousMigration", then delete it.

Reference:

http://elegantcode.com/2012/04/12/entity-framework-migrations-tips/



回答2:

If you haven't executed the migration yet with Update-Database, you can run Add-Migration again with the same name (you may need to use -Force) to re-execute the scaffolding. This is noted in the output of the Add-Migration command.



回答3:

With EntityFrameworkCore 2.0 comes the model snapshot. You will need to run the remove migration command in order to update the model snapshot. I have read that EF Core will recognize any update and revert the snapshot for you if you manually delete the migration but this has not worked for me.

https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/migrations

https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet#dotnet-ef-migrations-remove



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