4

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.

Paul Hennessey
  • 203
  • 5
  • 14

2 Answers2

6

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.

Brendan L
  • 1,436
  • 14
  • 13
5

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

Database-Update

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.

Ivan
  • 63,011
  • 101
  • 250
  • 382