我正在尝试使用命令dotnet ef migrations script
,以便在上次应用的迁移和最后一次未应用的迁移之间创建SQL脚本。应用迁移是一种称为dotnet ef database update
我尝试执行以下命令,但它们都不起作用:
dotnet ef --startup-project ../DbMigrations/ migrations script from LastAppliedMigration to LastNotAppliedMigration -o temp.sql --context MyProject.DbModel.MusicDbContext
dotnet ef --startup-project ../DbMigrations/ migrations script from LastAppliedMigration -o temp.sql --context MyProject.DbModel.MusicDbContext
我收到以下错误: System.InvalidOperationException:迁移'来自'没找到。
System.InvalidOperationException: The migration 'from' was not found.
at Microsoft.EntityFrameworkCore.Migrations.MigrationsAssemblyExtensions.GetMigrationId(IMigrationsAssembly assembly, String nameOrId)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.GenerateScript(String fromMigration, String toMigration, Boolean idempotent)
at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.ScriptMigration(String fromMigration, String toMigration, Boolean idempotent, String contextType)
at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsScriptCommand.Execute(CommonOptions commonOptions, String from, String to, String output, Boolean idempotent, String context, String environment)
at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsScriptCommand.<>c__DisplayClass0_0.<Configure>b__0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
对于迁移名称,我尝试了两个版本的前缀为timestamp且没有:
我是否正确使用此命令dotnet ef migrations script
?
修改1
我做了一个简单的例子来证明我的问题。该示例可以从这里下载Download example
我做了什么:
dotnet ef migrations add Initial
dotnet ef migrations script -o initial.sql
- 创建了initial.sql文件dotnet ef database update
Student
Data
课程
in
ApplicationDbContext``` dotnet ef migrations add Student
dotnet ef migrations script from 20160924174811_Initial -o student.sql
这里我收到以下错误 - 来自&#39;的迁移&#39;没找到。
Project WebApplication3 (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
System.InvalidOperationException: The migration 'from' was not found.
at Microsoft.EntityFrameworkCore.Migrations.MigrationsAssemblyExtensions.GetMigrationId(IMigrationsAssembly assembly, String nameOrId)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.GenerateScript(String fromMigration, String to Migration, Boolean idempotent)
at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.ScriptMigration(String fromMigration, String to Migration, Boolean idempotent, String contextType)
at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsScriptCommand.Execute(CommonOptions commonOptions, String from, String to, String output, Boolean idempotent, String context, String environment)
at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsScriptCommand.<>c__DisplayClass0_0.<Configure>b__0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
The migration 'from' was not found.
当我dotnet ef migrations list
时,我得到以下结果:
Project WebApplication3 (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
20160924174811_Initial
20160924175511_Student
CLI工具的版本是
dotnet --version
1.0.0-preview2-003131
答案 0 :(得分:1)
好的我明白了。
from
不是选项名称,其位置应直接来自迁移名称。
下面的工作命令示例:
dotnet ef migrations script Initial -o student.sql
或也有效
dotnet ef migrations script 20160924174811_Initial -o student2.sql