Is anyone else having problems with the second migration in Shawn Wildermuth's Pluralsight course "Building a Web App with ASP.NET Core RC1, MVC 6, EF7 & AngularJS"?

Specifically, the command

dnx ef migrations add IdentityEntities

causes this exception:

GenericArguments[0], 'TheWorld.Models.IWorldRepository', on 'Microsoft.Data.Entity.Infrastructure.IDbContextFactory`1[TContext]' violates the constraint of type 'TContext'.

The first migration and database creation seemed to go fine, so I'm not sure what's causing this.


I just fixed this by deleting the entire Migrations folder from Solution Explorer. I am not sure exactly what causes this error, but I think if you name your migrations the same thing (IdentityEntities in your case) the problem is likely to occur.


It seems like you should specify a migration name and the context explicitly as parameters. I am not sure what is it meant to look like when using dnx, but when using the Package Manager Console inside Visual Studio the correct command is

Add-Migration -Name "MyProjectMigration" -Context "MyProjectContext"

I have first tried simple

Add-Migration MyProjectContext

which has generated 2 files, and after that


and the result was the System.ArgumentException: GenericArguments[0], 'SqliteEfcExample.Migrations.MyProjectContext', on 'Microsoft.EntityFrameworkCore.Infrastructure.IDbContextFactory 1[TContext]' violates the constraint of type 'TContext'.

I have then deleted the 2 files generated by Add-Migration MyProjectContext (thanks to @brendan-l for the hint) and re-created them with Add-Migration -Name "MyProjectMigration" -Context "MyProjectContext" and after that

Update-Database -Context "MyProjectContext"

worked just fine.

Your Answer

