如何在Visual Studio 2012中降级Entity Framework 5迁移? [英] How do you downgrade a Entity Framework 5 migration in Visual Studio 2012?

查看:110
本文介绍了如何在Visual Studio 2012中降级Entity Framework 5迁移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,当我使用add-migration首先创建代码数据库迁移时,它会生成Down()方法和Up()方法.

I've noticed that when I create a code first database migration using add-migration it generates a Down() method as well as an Up() method.

如何告诉我的数据库降级?

How do I tell my database to downgrade?

推荐答案

在几乎放弃了对Google的研究之后,我设法从这里找到了这句话:

After almost giving up with researching on Google I managed to find this quote from here:

指定:

假设我们想将数据库迁移到运行AddBlogUrl迁移后的状态.我们可以使用–TargetMigration开关将其降级为该迁移.

Let’s say we want to migrate our database to the state it was in after running our AddBlogUrl migration. We can use the –TargetMigration switch to downgrade to this migration.

在程序包管理器控制台中运行Update-Database –TargetMigration: AddBlogUrl命令. 此命令将为我们的AddBlogAbstract和AddPostClass迁移运行Down脚本.

Run the Update-Database –TargetMigration: AddBlogUrl command in Package Manager Console. This command will run the Down script for our AddBlogAbstract and AddPostClass migrations.

如果要一直回滚到空数据库,则可以使用Update-Database –TargetMigration: $InitialDatabase命令.

If you want to roll all the way back to an empty database then you can use the Update-Database –TargetMigration: $InitialDatabase command.

这篇关于如何在Visual Studio 2012中降级Entity Framework 5迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆