简体   繁体   English

EF 4.3迁移 - 如何生成降级脚本?

[英]EF 4.3 Migration - how to produce a downgrade script?

I have an issue which I could not find answer for across the web. 我有一个问题,我无法通过网络找到答案。

I am using CodeFirst EF 4.3.1 Migrations with MsSQL. 我正在使用CodeFirst EF 4.3.1迁移与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? 任何想法如何生成降级脚本?

Thanks. 谢谢。

It looks like migration API expects that you want to do downgrade only from "last version". 看起来迁移API期望您只想从“上一版本”降级。

If BlogLimitsAndTableRename is your most recent migration (the last applied) you can simply run: 如果BlogLimitsAndTableRename是您最近的迁移(最后一次应用),您只需运行:

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. 现在你应该能够使用第一个命令来获取脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM