Pau*_*sey 4 migration entity-framework-core
是否有其他人在Shawn Wildermuth的Pluralsight课程"使用ASP.NET Core RC1,MVC 6,EF7和AngularJS构建Web应用程序"中遇到第二次迁移问题?
具体来说,命令
dnx ef migrations add IdentityEntities
Run Code Online (Sandbox Code Playgroud)
导致此异常:
GenericArguments[0], 'TheWorld.Models.IWorldRepository', on 'Microsoft.Data.Entity.Infrastructure.IDbContextFactory`1[TContext]' violates the constraint of type 'TContext'.
Run Code Online (Sandbox Code Playgroud)
第一次迁移和数据库创建似乎很顺利,所以我不确定是什么导致了这一点.
小智 6
我刚刚通过从Solution Explorer中删除整个Migrations文件夹来解决这个问题.我不确定是什么导致了这个错误,但我认为如果你将迁移命名为同一个东西(在你的情况下是IdentityEntities),则可能会出现问题.
似乎您应该明确指定一个迁移名称和上下文作为参数。我不确定使用dnx
时的外观,但是在Visual Studio中使用Package Manager Console时正确的命令是
Add-Migration -Name "MyProjectMigration" -Context "MyProjectContext"
Run Code Online (Sandbox Code Playgroud)
我首先尝试简单
Add-Migration MyProjectContext
Run Code Online (Sandbox Code Playgroud)
生成了2个文件,然后
Database-Update
Run Code Online (Sandbox Code Playgroud)
结果是 System.ArgumentException: GenericArguments[0], 'SqliteEfcExample.Migrations.MyProjectContext', on 'Microsoft.EntityFrameworkCore.Infrastructure.IDbContextFactory 1[TContext]' violates the constraint of type 'TContext'.
然后,我删除了生成的2个文件Add-Migration MyProjectContext
(感谢@ brendan-l的提示),Add-Migration -Name "MyProjectMigration" -Context "MyProjectContext"
并在此之后重新创建它们
Update-Database -Context "MyProjectContext"
Run Code Online (Sandbox Code Playgroud)
工作得很好。
归档时间: |
|
查看次数: |
2571 次 |
最近记录: |