I get Error when i run enable-migrations in package manager console

后端 未结 2 800
走了就别回头了
走了就别回头了 2020-12-30 05:50

I am making a ASP.NET MVC project ...when i type enable-migrations i get the following eroors:

More than one context type was found in the assembly \'eManage         


        
相关标签:
2条回答
  • 2020-12-30 06:11

    For those that may want to remain with a single context in the project. In this case, it will be the DepartmentDb context.

    Move the below code into your DepartmentDb context:

    public DepartmentDb() 
    : base("DefaultConnection")
    {
    
    }
    
    public DbSet<UserProfile> UserProfiles { get; set; }

    Next: Get to your AccountModels.cs and delete/comment out the UsersContext class. You will get build errors - so replace the UsersContext references with DepartmentDb.

    Build again and it should succeed.

    Now go to the Package Manager Console and run PM> enable-migrations

    You should get "Code First Migrations enabled for project eManager.Web."

    0 讨论(0)
  • 2020-12-30 06:32

    The error message exactly states what the problem is and what needs to be done - including the command that needs to be issued. Apparently there is more than one context in your project (Web.Infrastructure.DepartmentDb and Web.Models.UsersContext) and migrations does not know for which of these migrations should be enabled. You need to point to the context type. As per the error message use:

    Enable-Migrations -ContextTypeName eManager.Web.Infrastructure.DepartmentDb.
    

    to enable migrations for eManager.Web.Infrastructure.DepartmentDb or

    Enable-Migrations -ContextTypeName eManager.Web.Models.UsersContext.
    

    to enable migrations for eManager.Web.Models.UsersContext

    0 讨论(0)
提交回复
热议问题