Migration to/from not found while creating migration script with ASP.NET Core tools

asp.net-core ef-migrations entity-framework-core

Question

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:

  1. 20160920085915_LastAppliedMigration
  2. LastAppliedMigration

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:

  1. Created a default web application project
  2. dotnet ef migrations add Initial
  3. dotnet ef migrations script -o initial.sql -- the initial.sql file was created
  4. dotnet ef database update
  5. Added Student class in Data
  6. Added ``DbSetinApplicationDbContext
  • dotnet 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
    
    1
    2
    9/24/2016 6:26:02 PM

    Popular Answer

    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

    2
    9/24/2016 6:50:56 PM


    Related Questions





    Related

    Licensed under: CC-BY-SA with attribution
    Not affiliated with Stack Overflow
    Licensed under: CC-BY-SA with attribution
    Not affiliated with Stack Overflow