I am making a ASP.NET MVC project ...when i type enable-migrations i get the following eroors:
我正在做一个ASP。净MVC项目……当我输入使能-迁移时,我得到以下的eroors:
More than one context type was found in the assembly 'eManager.Web'.
To enable migrations for eManager.Web.Infrastructure.DepartmentDb, use Enable-Migrations -ContextTypeName eManager.Web.Infrastructure.DepartmentDb.
To enable migrations for eManager.Web.Models.UsersContext, use Enable-Migrations -ContextTypeName eManager.Web.Models.UsersContext.
2 个解决方案
#1
35
The error message exactly states what the problem is and what needs to be done - including the command that needs to be issued. Apparently there is more than one context in your project (Web.Infrastructure.DepartmentDb and Web.Models.UsersContext) and migrations does not know for which of these migrations should be enabled. You need to point to the context type. As per the error message use:
错误消息准确地指出问题是什么以及需要做什么——包括需要发出的命令。显然,您的项目中有多个上下文(Web.Infrastructure)。和迁移不知道应该启用哪些迁移。您需要指向上下文类型。根据错误信息的使用:
Enable-Migrations -ContextTypeName eManager.Web.Infrastructure.DepartmentDb.
to enable migrations for eManager.Web.Infrastructure.DepartmentDb or
为eManager.Web.Infrastructure启用迁移。DepartmentDb或
Enable-Migrations -ContextTypeName eManager.Web.Models.UsersContext.
to enable migrations for eManager.Web.Models.UsersContext
为eManager.Web.Models.UsersContext启用迁移
#2
1
For those that may want to remain with a single context in the project. In this case, it will be the DepartmentDb context.
对于那些希望在项目中保持单一上下文的人。在本例中,它将是DepartmentDb上下文。
Move the below code into your DepartmentDb context:
将以下代码移动到DepartmentDb上下文中:
public DepartmentDb()
: base("DefaultConnection")
{
}
public DbSet<UserProfile> UserProfiles { get; set; }
Next: Get to your AccountModels.cs and delete/comment out the UsersContext class. You will get build errors - so replace the UsersContext references with DepartmentDb.
接下来:查看你的账户模型。cs和删除/注释掉UsersContext类。您将得到构建错误——因此将UsersContext引用替换为DepartmentDb。
Build again and it should succeed.
再建一次,它就会成功。
Now go to the Package Manager Console and run PM> enable-migrations
现在转到包管理器控制台并运行PM>支持迁移
You should get "Code First Migrations enabled for project eManager.Web."
您应该获得“为project eManager.Web启用的代码第一次迁移”。
#1
35
The error message exactly states what the problem is and what needs to be done - including the command that needs to be issued. Apparently there is more than one context in your project (Web.Infrastructure.DepartmentDb and Web.Models.UsersContext) and migrations does not know for which of these migrations should be enabled. You need to point to the context type. As per the error message use:
错误消息准确地指出问题是什么以及需要做什么——包括需要发出的命令。显然,您的项目中有多个上下文(Web.Infrastructure)。和迁移不知道应该启用哪些迁移。您需要指向上下文类型。根据错误信息的使用:
Enable-Migrations -ContextTypeName eManager.Web.Infrastructure.DepartmentDb.
to enable migrations for eManager.Web.Infrastructure.DepartmentDb or
为eManager.Web.Infrastructure启用迁移。DepartmentDb或
Enable-Migrations -ContextTypeName eManager.Web.Models.UsersContext.
to enable migrations for eManager.Web.Models.UsersContext
为eManager.Web.Models.UsersContext启用迁移
#2
1
For those that may want to remain with a single context in the project. In this case, it will be the DepartmentDb context.
对于那些希望在项目中保持单一上下文的人。在本例中,它将是DepartmentDb上下文。
Move the below code into your DepartmentDb context:
将以下代码移动到DepartmentDb上下文中:
public DepartmentDb()
: base("DefaultConnection")
{
}
public DbSet<UserProfile> UserProfiles { get; set; }
Next: Get to your AccountModels.cs and delete/comment out the UsersContext class. You will get build errors - so replace the UsersContext references with DepartmentDb.
接下来:查看你的账户模型。cs和删除/注释掉UsersContext类。您将得到构建错误——因此将UsersContext引用替换为DepartmentDb。
Build again and it should succeed.
再建一次,它就会成功。
Now go to the Package Manager Console and run PM> enable-migrations
现在转到包管理器控制台并运行PM>支持迁移
You should get "Code First Migrations enabled for project eManager.Web."
您应该获得“为project eManager.Web启用的代码第一次迁移”。