EF 迁移:回滚上次应用的迁移? [英] EF Migrations: Rollback last applied migration?
问题描述
这看起来是一项非常常见的任务,但我找不到一种简单的方法来完成它.
This looks like a really common task, but I can't find an easy way to do it.
我想撤消上次应用的迁移.我本来希望有一个简单的命令,比如
I want to undo the last applied migration. I would have expected a simple command, like
PM> Update-Database -TargetMigration:"-1"
相反,我能想到的是:
PM> Get-Migrations
Retrieving migrations that have been applied to the target database.
201208012131302_Add-SystemCategory
201207311827468_CategoryIdIsLong
201207232247409_AutomaticMigration
201207211340509_AutomaticMigration
201207200025294_InitialCreate
PM> Update-Database -TargetMigration:"CategoryIdIsLong"
(至少我可以只用名字,跳过时间戳...)
(At least I can use just the name, skipping the timestamp...)
有没有更简单的方法?
推荐答案
从 EF 5.0 开始,您描述的方法是首选方法.所以
As of EF 5.0, the approach you describe is the preferred way. So
PM>Update-Database -TargetMigration:"NameOfSecondToLastMigration"
或使用您的示例迁移
PM>更新数据库 -TargetMigration:"CategoryIdIsLong"
一种解决方案是创建一个自动执行上述步骤的包装器 PS 脚本.此外,请随时为此创建功能请求,或者更好的是,尝试实现它!https://github.com/dotnet/ef6
One solution would be to create a wrapper PS script that automates the steps above. Additionally, feel free to create a feature request for this, or better yet, take a shot at implementing it! https://github.com/dotnet/ef6
这篇关于EF 迁移:回滚上次应用的迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!