EF 5 Enable-Migrations : No context type was found in the assembly

后端 未结 24 2012
野的像风
野的像风 2020-12-02 11:51

I have 4 projects :

Toombu.Entities : all models are there
Toombu.DataAccess: Mapping, Repository and ToombuContext
Toombu.Logique : Logic of my application         


        
相关标签:
24条回答
  • 2020-12-02 12:49

    I got this problem first: PM> add-migration first

    No migrations configuration type was found in the assembly 'MyProjectName'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).

    then i tried this:

    PM> Enable-Migrations No context type was found in the assembly 'MyProjectName'.

    Then the right command for me :

    PM> Enable-Migrations -ProjectName MyProjectName -ContextTypeName MyProjectName.Data.Context

    After that i got this error message even though Context inherits from DbContext

    The type 'Context' does not inherit from DbContext. The DbMigrationsConfiguration.ContextType property must be set to a type that inherits from DbContext.

    Then i Installed Microsoft.EntityFrameworkCore.Tools

    ITS OK NOW but the message is funny. i already tried add migrations at first :D

    Both Entity Framework Core and Entity Framework 6 are installed. The Entity Framework Core tools are running. Use 'EntityFramework6\Enable-Migrations' for Entity Framework 6. Enable-Migrations is obsolete. Use Add-Migration to start using Migrations.

    0 讨论(0)
  • 2020-12-02 12:50

    If anyone is still facing this problem. I solved it by using the following command:

    Enable-Migrations -ProjectName <YOUR_PROJECT_NAME> -ContextTypeName <YOUR_CONTEXT_NAME>
    

    Don't forget to use the full path to your context name.

    0 讨论(0)
  • 2020-12-02 12:51

    Change the default project and choose the startup project from dropdown:

    0 讨论(0)
  • 2020-12-02 12:51

    I had to do a combination of two of the above comments.

    Both Setting the Default Project within the Package Manager Console, and also Abhinandan comments of adding the -ContextTypeName variable to my full command. So my command was as follows..

    Enable-Migrations -StartUpProjectName RapidDeploy -ContextTypeName RapidDeploy.Models.BloggingContext -Verbose
    

    My Settings::

    • ProjectName - RapidDeploy
    • BloggingContext (Class Containing DbContext, file is within Models folder of Main Project)
    0 讨论(0)
  • 2020-12-02 12:52

    How to Update table and column in mvc using entity framework code first approach

    1: tool > package manager console

    2: select current project where context class exist

    3: Enable migration using following command PM > enable-migrations

    4: Add migration folder name using following command PM > add-migration MyMigrationName

    4: Now update database following command PM > update-database

    0 讨论(0)
  • 2020-12-02 12:53

    Worked for me:

     UnInstall-Package EntityFramework 
    
    • Restart Visual Studio

    Install-Package EntityFramework

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