EF Core 2.0 Migration - dotnet ef migrations 'script' command outputting blank file

Viewed 13648

I have recently migrated my web project to Asp.Net Core 2.0 and Entity Framework Core 2.0.

The web application is working correctly and all dotnet ef migrations CLI commands are working apart from the following:

dotnet ef migrations script {migrationname1} {migrationname1} -o my-file-name.sql

The query appears to run with no errors and then produces no SQL code either to screen or file.

I am using Visual Studio 2017 with SQL Server Express (localdb) on Windows.

Just wondering if anyone else has come across the issue since migrating?

Would appreciate some help as can not find anything on here or Google.

3 Answers

After lots of wasted effort and time, it looks like this is a bug with dotnet ef migrations script, as this is not functioning as it did in EF Core 1.0.

Script-Migration -From 20171106124427_061120171243

Outputs blank

Script-Migration -From 20171106124427_061120171243 -To 20171106124427_061120171243

Outputs blank (note the -From and -To values are the same)

Script-Migration 20171106124427_061120171243

Outputs blank

Script-Migration -From 20171106122611_061120171225 -To 20171106124427_061120171243

Outputs SQL statements as expected (Note -From and -To values are different)

I get the same results whether I try this in Visual Studio 2017 Package Manager Console or the CLI.

After further investigation it would appear the answer lies in the following:

Script-Migration -From <PreviousMigration> -To <LastMigration>

It would appear that it is my misunderstanding of the -From and -To attributes that is the problem regardless of whether this used to work in a previous version.

I had incorrectly assumed that the -From migration file would be included in the resulting code generation, but after some testing this does not seem to be the case.

dotnet ef migrations script FromA FromB 

This will get the script generated in the terminal itself

If you want to generate to a file use this option

dotnet ef migrations script FromA FromB -o sample.sql
Related