I am trying to use the command dotnet ef migrations script
in order to create an SQL script for between the last applied migration and the last not applied migration. Applied migration is one for which is called dotnet ef database update
I try to execute the following commands and none of them works:
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
I get the following error: System.InvalidOperationException: The migration 'from' was not found.
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)
For migration names I tried both versions with the prefix timestamp and without:
Do I use this command dotnet ef migrations script
correctly?
Edit 1
I did a simple example to demonstrate the issue which I have. The example can be downloaded from here Download example
What I did:
dotnet ef migrations add Initial
dotnet ef migrations script -o initial.sql
-- the initial.sql file was createddotnet ef database update
Student
class in Data
in
ApplicationDbContextdotnet ef migrations add Student
dotnet ef migrations script from 20160924174811_Initial -o student.sql
Here I get the following error -- The migration 'from' was not found.
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.
When I do dotnet ef migrations list
I get the following result:
Project WebApplication3 (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
20160924174811_Initial
20160924175511_Student
The version of the CLI tools is
dotnet --version
1.0.0-preview2-003131
Ok I figured it out.
from
is not an option name and on its place should come directly the migration name.
Working command examples below:
dotnet ef migrations script Initial -o student.sql
or also is valid
dotnet ef migrations script 20160924174811_Initial -o student2.sql