EF 4.3迁移 - 如何生成降级脚本? [英] EF 4.3 Migration - how to produce a downgrade script?

查看:466
本文介绍了EF 4.3迁移 - 如何生成降级脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我无法在网路上找到答案。

I have an issue which I could not find answer for across the web.

我正在使用CodeFirst EF 4.3.1使用MsSQL进行迁移。

I am using CodeFirst EF 4.3.1 Migrations with MsSQL.

我已经添加了几个迁移,现在我要生成两个迁移之间的升级/降级脚本。

I have added several migrations and now I want to produce a script for upgrade/downgrade between two migrations.

对于升级我运行以下命令成功重现升级脚本:

For upgrade I run the following command which successfully reproduces an upgrade script:

PM> Update-Database -Script -SourceMigration:"201205161144187_AddPostAbstract" -TargetMigration:"201205161203310_BlogLimitsAndTableRename"

但是,我运行以下命令失败,出现以下错误:

However, for downgrade I run the following command which fails with the following error:

PM> Update-Database -Script -SourceMigration:"201205161203310_BlogLimitsAndTableRename" -TargetMigration:"201205161144187_AddPostAbstract"
Scripting the downgrade between two specified migrations is not supported.

任何想法如何生成降级脚本?

Any ideas how can I generate a downgrade script?

谢谢。

推荐答案

看起来像迁移API希望你只想从最后一个版本进行降级。

It looks like migration API expects that you want to do downgrade only from "last version".

如果 BlogLimitsAndTableRename 是您最近的迁移(最后一次应用),您可以简单地运行:

If BlogLimitsAndTableRename is your most recent migration (the last applied) you can simply run:

Update-Database -Script -TargetMigration:"201205161144187_AddPostAbstract"

如果不是您的最后一次迁移,您需要首先将开发数据库还原到其中:

If it is not your last migration you need to revert your development database to it first:

Update-Database -TargetMigration:"201205161203310_BlogLimitsAndTableRename"

现在你应该可以使用第一个命令得到一个脚本。

and now you should be able to use the first command to get a script.

这篇关于EF 4.3迁移 - 如何生成降级脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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