Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migration: No DbContext was found in assembly

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; } 
like image 519
cembo Avatar asked Oct 11 '17 03:10

cembo


People also ask

How do I enable migrations in Visual Studio?

From the Tools menu, select NuGet Package Manager > Package Manager Console. The enable-migrations command creates a Migrations folder in the ContosoUniversity project, and it puts in that folder a Configuration. cs file that you can edit to configure Migrations.

How do I add a migration to EF?

Open the Package Manager Console from Tools → Library Package Manager → Package Manager Console and then run the enable-migrations command (make sure that the default project is the project where your context class is).


2 Answers

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

like image 67
Vamsi J Avatar answered Sep 30 '22 18:09

Vamsi J


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.

like image 31
Wiff1 Avatar answered Sep 30 '22 19:09

Wiff1