【问题标题】:Unable to add migration on Entity Framework无法在实体框架上添加迁移
【发布时间】:2020-10-23 04:53:08
【问题描述】:

尝试添加迁移 add-migration "Inicial" -Verbose 时,会出现以下错误消息:
No migrations configuration type was found in the assembly 'DevIO.UI.Site'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).

我按照消息说明输入命令Enable-Migrations,但还是报错
No context type was found in the assembly 'DevIO.UI.Site'

我能做什么?

【问题讨论】:

  • 它仍然不能解决我的问题。我不断收到消息:在程序集“DevIO.UI.Site”中找不到上下文类型。
  • 您的屏幕截图中的错误与您的问题中的错误不同。在屏幕截图中,您输入了StartUpProjectName AppModelo2,但这是您的解决方案的名称,而不是项目的名称。你的项目是DevIO.UI.Site
  • 这是我尝试过的众多方法之一。
  • 您尝试使用哪个版本的实体框架?您的屏幕截图显示using Microsoft.EntityFrameworkCore,但您已将问题标记为entity-framework,而不是entity-framework-core。对于 EF 6 或更低版本,上下文应位于 System.Data.Entity 中,您似乎没有使用它。

标签: entity-framework-core entity-framework-migrations


【解决方案1】:

假设您的解决方案中已经有一个 DbContext 类,您需要知道它在哪个项目中。您应该在该项目中添加迁移。如果您为此使用 Visual Studio 包管理器控制台,则需要将默认项目设置为包含 DbContext 的项目(即在包管理器控制台顶部的下拉列表中)。

【讨论】:

  • 默认项目匹配:DevIO.UI.Site
【解决方案2】:

Entity Framework 与 Entity Framework Core 不同。您正在使用实体框架(我们知道这是因为 EF Core 不包含 Enable-Migrations 命令),但您的 DbContext 来自 Microsoft.EntityFrameworkCore 命名空间。如果您将using Microsoft.EntityFrameworkCore 替换为using System.Data.Entity,那应该是Entity Framework 的正确DbContext 类。

【讨论】:

    【解决方案3】:

    我想如果你安装一个名为 Microsoft.EntityFrameworkCore.Tools 的 NuGet 包,它会解决这个问题。

    【讨论】:

      猜你喜欢
      • 2018-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-20
      • 2013-04-02
      • 2019-02-25
      • 1970-01-01
      • 2015-05-11
      相关资源
      最近更新 更多