Reputation: 144
While running command enable-migrations in Package Manager Console, got this error:
No context type was found in the assembly 'Vidly'
I am using Visual Studio 2017. How to solve it?
Upvotes: 7
Views: 17595
Reputation: 21
I have faced this problem and get it done my doing this
Upvotes: 2
Reputation: 101
I have encountered this problem a few times and in my case I
That fixed the problem for me
Upvotes: 3
Reputation: 391
In order to resolve the issue, please find below steps.
Add this namespace System.Data.Entity for DbContext reference
using System.Data.Entity;
namespace Vidly.Models
{
public class MyDBContext:DbContext
{
public MyDBContext()
{
}
public DbSet<Customer> Customers { get; set; } // My domain models
public DbSet<Movie> Movies { get; set; }// My domain models
}
}
Now open package manager console and type below command to enable migrations.
enable-migrations -contexttypename MyDBContext (MyDBContext is the name of the class we created in step1)
Hope this helps :)
Upvotes: 29
Reputation: 1562
Make sure you have set the Default Project, that is present at the top label with a dropdown in your Package Manager Console. And this project should contains your Entity Framework context.
You can check this post to find where Default Project drop down located.
So finaly your code should be like this,
Enable-Migrations -ProjectName MyContextProjectNameHere -StartUpProjectName MyStartUpProjectNameHere -Verbose
Hope it helps :)
Upvotes: 9