Gab*_*ada 50 .net entity-framework entity-framework-core asp.net-core-mvc asp.net-core
我正在使用.Net Core构建MVC应用程序,我需要生成迁移脚本.
使用EF6,我确实运行了命令
update-database -script
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用.net时也是如此.
Update-Database:找不到与参数名称'script'匹配的参数
你知道EF7是否有相同的产品吗?
小智 82
根据EF文档,您可以使用Script-Migration命令.
如果您只想编写所有迁移的脚本,只需从Package Manager控制台中调用它即可.如果您只想编写上次迁移的更改脚本,可以像下面这样调用它:
Script-Migration -From <PreviousMigration> -To <LastMigration>
Run Code Online (Sandbox Code Playgroud)
一定要检查文档,这个命令还有一些选项.
小智 26
dotnet ef migrations script --help
Usage: dotnet ef migrations script [arguments] [options]
Arguments:
<FROM> The starting migration. Defaults to '0' (the initial database).
<TO> The ending migration. Defaults to the last migration.
Options:
-o|--output <FILE> The file to write the result to.
-i|--idempotent Generate a script that can be used on a database at any migration.
-c|--context <DBCONTEXT> The DbContext to use.
-p|--project <PROJECT> The project to use.
-s|--startup-project <PROJECT> The startup project to use.
--framework <FRAMEWORK> The target framework.
--configuration <CONFIGURATION> The configuration to use.
--runtime <RUNTIME_IDENTIFIER> The runtime to use.
--msbuildprojectextensionspath <PATH> The MSBuild project extensions path. Defaults to "obj".
--no-build Don't build the project. Only use this when the build is up-to-date.
-h|--help Show help information
-v|--verbose Show verbose output.
--no-color Don't colorize output.
--prefix-output Prefix output with level.
Run Code Online (Sandbox Code Playgroud)
所以,你可以试试
dotnet ef migrations script ver1 ver2
dotnet ef migrations script ver1 ver2 -o ./script.sql
Run Code Online (Sandbox Code Playgroud)
这适用于 .Net Core 2.1
Ahm*_*mar 12
您可以使用dotnet core cli生成脚本
dotnet ef migrations script
Run Code Online (Sandbox Code Playgroud)
您也可以使用新的power shell out-file命令将其置于文件中.
dotnet ef migrations script | out-file ./script.sql
Run Code Online (Sandbox Code Playgroud)
您还可以通过将参数反转为“脚本迁移”来生成脚本以回滚迁移。例如,如果您有两个迁移BadLatestMigration和GoodPreviousMigration,则可以使用以下命令还原为GoodPreviousMigration
Script-Migration BadLatestMigration GoodPreviousMigration
Run Code Online (Sandbox Code Playgroud)
之后,请确保删除-迁移以删除错误的迁移
Remove-Migration
Run Code Online (Sandbox Code Playgroud)
这适用于.Net Core 2.2.0
这也只生成 SQL
Update-Database -script -TargetMigration TO -SourceMigration FROM
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
41788 次 |
| 最近记录: |