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.
4条答案
按热度按时间66bbxpm51#
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.Outputs blank
Outputs blank (note the -From and -To values are the same)
Outputs blank
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:
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.
xnifntxz2#
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:
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:
This will end up silently failing and opening up an empty SQL file! Drat!
This is the command you want to run:
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.EDIT:
Above are PowerShell commands for the Package Manager Console. The answer by @Suraj is helpful if you are using
dotnet ef migrations
from the command line. (You need to use the FROM and TO arguments).ocebsuys3#
This will get the script generated in the terminal itself
If you want to generate to a file use this option
fnatzsnv4#
Note that if you are creating your initial Script-Migration then leave the migration name blank. Leaving the migration name blank will also script the entire database.
So, for example, this will return a blank sql file in a project with one migration named InitialCreate:
Script-Migration InitialCreate
While this would return the correct sql file:
Script-Migration