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

时间:2020-07-02 14:40:04

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

当尝试添加迁移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'

我该怎么办?

enter image description here

3 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

答案 2 :(得分:0)

我认为,如果安装名为Microsoft.EntityFrameworkCore.Tools的NuGet软件包,它将解决此问题。