在 Entity Framework 6 中,我需要获取特定迁移文件的 SQL 脚本,并且我已经更新了数据库。我发现在 update-database
命令我可以添加脚本参数以将迁移导出到 SQL,但我已经更新了数据库。我在 Entity Framework Core 中找到了一个名为 Script-Migration
的命令以脚本名称作为参数。 Entity Framework 中是否有类似的命令?
我也尝试了建议“Update database command”,但我得到了一个空的 SQL 文件。
最佳答案
是的,您可以按如下方式生成迁移 SQL:
Update-Database -Script -SourceMigration: <pointFromWichYouWantToStartWithGeneration> -TargetMigration: <pointWhereToEndWithGeneration>
要为所有迁移创建脚本,请执行以下操作:
Update-Database -Script -SourceMigration: $InitialDatabase
它不会将更改应用于数据库,而是会生成一个 SQL 脚本文件。因此,即使迁移已应用于数据库,您也可以生成 SQL 脚本。
在这里你可以找到更多关于它的信息 - Entity Framework Code First Migrations - Getting a SQL Script .
Run the
Update-Database
command but this time specify the–Script
flag so that changes are written to a script rather than applied. We’ll also specify a source and target migration to generate the script for.
关于entity-framework - 在 Entity Framework 6 C# 中获取特定迁移的 SQL 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49552550/