Nikola Schou
Nikola Schou

Reputation: 2466

Entity Framework 7 "dnx ef migrations add" missing output file

The EF7 command

dnx ef migrations add XXX 

suddenly stopped working. It gives the normal output to the console...

C:\Users\Nikola\Dev\ScanburSandbox\src\ScanburSandbox>dnx ef migrations add XXX
Done. To undo this action, use 'ef migrations remove'

...but the usual .cs and .designer.cs files are not produced.

Question: Can anyone suggest why this can happen or how I can troubleshoot it?

Some more details:

The content of the Migrations-folder before and after running the command looks like this:

11-02-2016  00:03             7.629 00000000000000_CreateIdentitySchema.cs
11-02-2016  00:03             6.637 00000000000000_CreateIdentitySchema.Designer.cs
11-02-2016  00:08             9.688 20160210230810_modelv2.cs
11-02-2016  00:08            10.103 20160210230810_modelv2.Designer.cs
12-02-2016  15:38             8.636 20160212083018_modelv3.cs
12-02-2016  15:38            10.065 20160212083018_modelv3.Designer.cs
12-02-2016  15:38            10.058 ApplicationDbContextModelSnapshot.cs

I have been running the EF7-tools ("dnx ef migrations" and "dnx ef database") with success many times up to now, each time with the expected outcome. This means that "dnx ef migrations add XXX" will add a new .cs and .designer.cs file every time it is executed. This will happen no matter if the model classes have changes or not.

I have no idea how to troubleshoot this tool. I don't see any debug flag or any log-files written anywhere. I don't see any errors in the output.

I really hope someone has bright ideas as I'm stuck here.

Upvotes: 3

Views: 688

Answers (3)

Nikola Schou
Nikola Schou

Reputation: 2466

After some more research I finally realized why the migration files were missing.

I ran again with the verbose flag: dnx ef migrations add v3 -v

This is the output:

Finding DbContext classes...
Using context 'ApplicationDbContext'.
An operation was scaffolded that may result in the loss of data. Please review the migration for accuracy.
Reusing directory of file '00000000000000_CreateIdentitySchema.cs'.
Reusing directory of file 'ApplicationDbContextModelSnapshot.cs'.
Writing migration to
'c:\Users\Nikola\Dev\SdmWeb\src\SdmWeb\bin\output\approot\src\SdmWeb\Migrations\20160223195618_v1.cs'.
Writing model snapshot to
'c:\Users\Nikola\Dev\SdmWeb\src\SdmWeb\bin\output\approot\src\SdmWeb\Migrations\ApplicationDbContextModelSnapshot.cs'.
Done. To undo this action, use 'ef migrations remove'

The tricky point here is, that it is 'reusing directory of...' and then later on it says that it is writing the migrations files to ...\bin\output\approot\src.

After cleaning the bin-folder and running again, the migration files are produced in the Migration folder directly under ...\Migrations as expected.

Upvotes: 1

user1748837
user1748837

Reputation: 11

I'm having the same problem, I haven't had much luck with specifying the project, context, and output directory. It seems like it's just stalling out and not doing anything. I've also tried running it in an Administrator powershell in-case it's some permission issue, but still nothing.

Edit: I tried adding a new migration on a linux machine and that seemed to create the migration fine. Creating migrations afterwards seems to work perfectly now.

Upvotes: 1

Sergey Barskiy
Sergey Barskiy

Reputation: 1803

Do you have more than on DbContext or multiple projects? I am guessing your files are written elsewhere if you are not getting an error. Try to specify all the options for dnx ef migrations add XXX, like output dir, project name and context class name. You can see all the available options for the command if you type the following command in the project folder. I would specify all of them and see what the result it. You may need to use new migration name to ensure you can safely track command results. dnx ef migrations add --help

Upvotes: 0

Related Questions