无法在实体框架上添加迁移

问题描述 投票:0回答:4

尝试添加迁移时

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'

我能做什么?

entity-framework-core entity-framework-migrations
4个回答
0
投票

假设您的解决方案中已经有一个

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


0
投票

Entity Framework 与 Entity Framework Core 不同。您正在使用实体框架(我们知道这是因为 EF Core 不包含

Enable-Migrations
命令),但您的
DbContext
来自
Microsoft.EntityFrameworkCore
命名空间。如果将
using Microsoft.EntityFrameworkCore
替换为
using System.Data.Entity
,这应该是实体框架的正确
DbContext
类。


0
投票

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


0
投票

这个问题是如何解决的?我已经循环运行了大约两天,没有办法解决我自己的项目中的这个确切问题

© www.soinside.com 2019 - 2024. All rights reserved.