Migration: No DbContext was found in assembly

cembo picture cembo · Oct 11, 2017 · Viewed 30.8k times · Source

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; }

Answer

Vamsi J picture Vamsi J · Jun 10, 2018

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