asp.net-mvc - 在包管理器控制台中运行 enable-migrations 时出现错误

标签 asp.net-mvc entity-framework

我正在制作一个 ASP.NET MVC 项目......当我输入 enable-migrations 时,我得到以下内容:

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.

最佳答案

错误消息准确说明了问题所在以及需要执行的操作 - 包括需要发出的命令。显然,您的项目中有多个上下文(Web.Infrastructure.DepartmentDb 和 Web.Models.UsersContext)并且迁移不知道应该为这些迁移中的哪一个启用。您需要指向上下文类型。根据错误消息使用:

Enable-Migrations -ContextTypeName eManager.Web.Infrastructure.DepartmentDb.

启用 eManager.Web.Infrastructure.DepartmentDb 的迁移或
Enable-Migrations -ContextTypeName eManager.Web.Models.UsersContext.

为 eManager.Web.Models.UsersContext 启用迁移

关于asp.net-mvc - 在包管理器控制台中运行 enable-migrations 时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13471444/

相关文章:

asp.net-mvc - 在 ASP.NET MVC 中创建模型

c# - 在 MVC 中使用 LocalDb 从 App_Data 文件夹中删除数据库时出现 "Cannot attach the file"错误?

asp.net - 在 ASP.NET MVC 3 中为未经身份验证的用户缓存主页

c# - 如何向绑定(bind)到实体的组合框添加新项目?

c# - Entity Framework 不包括选择语句中的列

c# - 用 Moq 替换 Setup 的值

c# - 在 .net 核心 mvc 应用程序上存储用户密码的最佳方式

c# - 在某些情况下禁用 Required 验证属性

asp.net - 具有自定义模型和 OData 的 Entity Framework 5 - Web API

vb.net - MVC 5 - 从 IdentityDbContext 和 IdentityUser 继承时,EF 6.1 脚手架失败