I have 4 projects :
Toombu.Entities : all models are there
Toombu.DataAccess: Mapping, Repository and ToombuContext
Toombu.Logique : Logic of my application
Toombu.Web : MVC 4 application. With all others DLL.
I tried to enable migration in Toombu.Web but i had this error :
No context type was found in the assembly
How can I enable migration ?
Change the default project to data access
change the default project dropdown in the package manager console to data access and give enable migrations...
Thats all success
How to Update table and column in mvc using entity
framework code
first approach1: 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
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..
My Settings::
use -ProjectName option in Package Manager Console:
I am surprised that no one mentioned the obvious answer to this question: Entity Framework requires a context before enable-migrations will work. The error message the OP posted suggests that no context was found. Sure, it could be because the package manager console doesn't "see" the context--in which case the accepted answer is a possible solution (another solution is one I suggest, below). But a context must exist in the current project (assembly) before any other solutions will work.
What does it mean to have a context? It means that there must exist a class in your project that inherits from DbContext (in System.Data.Entity). Here is an example:
Be sure you use
before the code above has access to the DbContext class and that you have used NuGet to get Entity Framework 4.1 or later for the current project.
If all along you had a context but the Package Manager Console just doesn't "see" it: In Visual Studio 2013 you don't have to use the -ProjectName switch. Instead, go to the Package Manager Console (it's available in the View | Other Windows list), and look at the two dropdowns that appear at the top of the Package Manager Console dockable window. The first dropdown is for Package Source; the second is for Default Project. If you dropdown the Default Project and select a project in your solution then whatever commands you issue in the Package Manager console will be executed against the selected project.
Thanks for the suggestions, I solved the problem by combining all the solutions here. At first I created the DbContext Model:
After creating the dbcontext class, I ran the enable-migration command with the project Name: enable-migrations -ProjectName YourProjectName