Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 433
Martin Bee Avatar asked Nov 06 '17 15:11

Martin Bee


People also ask

How do I create an empty migration EF core?

In Package Manager Console in Visual Studio, add an empty migration targeting your Database context. It'll create an empty migration provided you don't have any other DB changes to be applied.


1 Answers

E. Gads. LOL

I have come up with the answer and it is so ridiculous.

Here is the syntax you use to add a migration:

Add-Migration MigrationName -Context MyDbContext

Because I like to save time I up arrow and down arrow in the Package Manager Console to recall previous commands. If you recall the command and change Add-Migration to Script-Migration you will end up runnig:

Script-Migration MigrationName -Context MyDbContext

This will end up silently failing and opening up an empty SQL file! Drat!

This is the command you want to run:

Script-Migration -Context MyDbContext

Then it will work. If this is not your problem, sorry. I found that adding the -v option to the command is quite revealing and I would suggest that you try it.

like image 175
Jess Avatar answered Oct 05 '22 00:10

Jess