问题描述
我在一个 C# 项目中有多个 DbContext
,我正在尝试启用迁移.当我指定完整的命令时,即:
I have multiple DbContext
s in a C# project and I'm trying to enable migrations. When I specify the full command, i.e.:
Enable-Migrations -ContextTypeName Models.Account.AccountDetailDbContext
使用配置类创建了一个迁移文件夹,但随后我收到一条消息:
A migrations folder is created, with the configuration class, but I then get a message:
检查上下文是否针对现有数据库...
Checking if the context targets an existing database...
然后
在程序集Portal.WebUI"中找不到迁移配置类型Portal.WebUI.Migrations.Configuration".
The migrations configuration type 'Portal.WebUI.Migrations.Configuration' was not be found in the assembly 'Portal.WebUI'.
即使它刚刚创建了文件,也找不到它.
Even though it has just created the file, it can't find it.
我在包管理器控制台中选择了正确的项目
I have the correct project selected in the Package Manager Console
我已尝试使用 -verbose
的命令,但它没有提供额外信息
I have tried the command using -verbose
, but it gives no additional information
如果我将 dbcontexts 和类复制到一个新项目中,那么一切正常,所以它一定是这个现有项目中的某些东西导致迁移失败,但我不知道它是什么.
If I copy the dbcontexts and classes into a new project then it all works, so it must be something in this existing project that is making the migration fail, but I can't tell what it is.
推荐答案
我通过在Add-Migration
前添加EntityFrameworkCore
解决了这个问题,即最终语句为:
I solved this by adding EntityFrameworkCore
before Add-Migration
, i.e. the final statement was:
EntityFrameworkCoreAdd-Migration
在为您的新迁移命名之后.
After give a name for your new migration.
这篇关于实体框架 - 在程序集中找不到迁移配置类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!