[英]No context type was found in the assembly - The type 'ApplicationDbContext' does not inherit from DbContext
When I am trying to update the database It is throwing the following error.当我尝试更新数据库时,它抛出以下错误。 Please note that update-database cmd used to work fine with me before.请注意,update-database cmd 以前对我来说很好用。
No migrations configuration type was found in the assembly 'Tycoon'.在程序集“Tycoon”中找不到迁移配置类型。 (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration). (在 Visual Studio 中,您可以使用包管理器控制台中的 Enable-Migrations 命令添加迁移配置)。
I have tried Enable-Migrations but when I do that I get the following error.我尝试过启用迁移,但是当我这样做时,我收到以下错误。
No context type was found in the assembly 'Tycoon'.在程序集“Tycoon”中找不到上下文类型。
And then I tried this然后我尝试了这个
Enable-Migrations -ProjectName <YOUR_PROJECT_NAME> -ContextTypeName <YOUR_CONTEXT_NAME>
but got the following error.但出现以下错误。
The type 'ApplicationDbContext' does not inherit from DbContext. “ApplicationDbContext”类型不是从 DbContext 继承的。 The DbMigrationsConfiguration.ContextType property must be set to a type that inherits from DbContext DbMigrationsConfiguration.ContextType 属性必须设置为从 DbContext 继承的类型
I am building MVC application with Individual User accounts hence ApplicationDbContext
class was created by default which is inherited from IdentityDbContext
.我正在使用个人用户帐户构建 MVC 应用程序,因此ApplicationDbContext
类是默认创建的,它是从IdentityDbContext
继承的。
Please note that I was able to do migrations before but I am not sure why is it throwing errors now.请注意,我之前可以进行迁移,但我不确定为什么现在会抛出错误。
如果您的上下文文件的名称是 ApplicationDbContext,请尝试从基类 DbContext 派生它,如下所示:
public class ApplicationDbContext : DbContext
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.