简体   繁体   English

实体框架6从代码优先迁移中获取SQL

[英]Entity Framework 6 get the sql from code first migration

I want to get the sql of some migrations that were already executed on my developer machine, so I can execute them on some other enviroment(qa, prod, ...). 我想获取已经在我的开发人员机器上执行过的某些迁移的sql,因此我可以在其他环境(qa,prod等)上执行它们。 I found this page http://msdn.microsoft.com/en-us/data/jj591621.aspx (section Getting a SQL Script ), but this works only if you have pending migrations. 我发现此页面http://msdn.microsoft.com/zh-cn/data/jj591621.aspx (“ 获取SQL脚本”部分 ),但这仅在您有挂起的迁移时才有效。 I tried: 我试过了:

Update-Database -Script -SourceMigration: $InitialDatabase -TargetMigration: SomeMigration

but got Target database is already at version SomeMigration. 但是获得的Target database is already at version SomeMigration.

Can I get the sql of already executed migration? 我可以获取已经执行的迁移的SQL吗?

EF6, MVC5, VisualStudio 2013 EF6,MVC5,VisualStudio 2013

Well, it does exactly what it should since you invoke Update-Database on your local environment. 好吧,它的作用完全一样,因为您在本地环境上调用了Update-Database

If you need to generate update script for another environment I see the following options: 如果您需要为另一个环境生成更新脚本,请参见以下选项:

  • You can target your local application to the database from remote environment . 您可以将本地应用程序从远程环境定位到数据库 In this case it is enough to change connection string in your web.config manually. 在这种情况下,只需在web.config手动更改连接字符串即可。

  • You can revert your local database to the state of the database that your remote environment is targeting . 您可以将本地数据库恢复为远程环境定位的数据库状态 Update-Database –TargetMigration: "last migration on remote environment"

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

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