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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With