Migration: No DbContext was found in assembly

52,689

Solution 1

In the Package Manager Console select the project where the DbContext is defined and run the command add-migration initial. For example:public class SomeContext : DbContext

Solution 2

You have to specify the project name where the DbContext is located. So just right on the Nugget PM Console, type: Add-Migration MigrationName -Project YourProjectName.

Solution 3

Using the nuget package manager, I had installed all the EntityFrameworkCore dependencies, along with the EntityFramework 6 dependency. Visual Studio was using EF Core, when I needed it to be using EF 6. Uninstalling all EF Core dependencies resolved this issue.

Share:
52,689
cembo
Author by

cembo

Updated on February 09, 2022

Comments

  • cembo
    cembo about 2 years

    Using VS Community 2017. I have tried to create initial migration with error message saying:

    Both Entity Framework Core and Entity Framework 6 are installed. The Entity Framework Core tools are running. Use 'EntityFramework\Add-Migration' for Entity Framework 6. No DbContext was found in assembly 'Test_Project'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic.

    ... code in my dbcontext:

    protected override void OnModelCreating(DbModelBuilder mb)
    {
        base.OnModelCreating(mb);
    
        mb.Entity<Stuff>().ToTable("Stuff");
    
    }
    
    public DbSet<Stuff> Stuff{ get; set; }