I created a library based on .NET 4.6.2 version.
To the library, I\'ve added the EntityFramework version 6.1.3 package.
I created a model as follow
To be free from defining startup project explicitly , you can use the command:
Enable-Migrations -EnableAutomaticMigrations -ProjectName Components -StartupProjectName Components
The parameters are:
-ProjectName
Specifies the project that the scaffolded migrations configuration class will be added to (configuration.cs). If omitted, the default project selected in package manager console is used.
-StartUpProjectName
Specifies the configuration file to use for named connection strings. If omitted, the specified project's configuration file is used.
To get more details for the command, run:
get-help enable-migrations -Full
if anyone is using visual studio 2017 then you might have to check for the following packages
Nuget Packages
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.Tools
Microsoft.EntityFrameworkCore.SqlServer
after that run the migrations command below on console
EntityFrameworkCore\Enable-Migrations
EntityFrameworkCore\Add-Migration Book
2018 update - if the accepted answer doesn't help, see this github issue on the EF6 repository.
Apparently code migration commands don't work with the new project format. In order for the migrations commands to work, you need to create a Class Library (.NET Framework)
project (old standard), move all the files there, add all the needed dependencies and run the command.
EDIT: I just ran into this problem by creating a Class Library (.NET Standard)
project on VisualStudio 2017 15.6.6 using EntityFramework 6.2.0. Creating an "old standard" project as explained above fixes it.
I also had 2 versions of EF installed and using "EntityFrameworkCore\Add-Migration [migrationname]" command to specify which version to use solved the issue.
This can happen if you have both Microsoft.EntityFrameworkCore.SqlServer installed alongside an older version of EntityFramework say 6.x
In Visual Studio, go to Project/Manage Nuget Packages...
Take a look through the Installed list and if more than one version of EntityFramework is installed, uninstall all older versions, leaving only the latest version.
Edit: Simple fix (as stated above) -StartupProjectName YourEF6ProjectNameHere
When I had been using the wrong StartupProjectName I still got the error. That's when I was using the solution below:
My kludgy work-around is to unload the project that does not require EF migrations:
Unload Project
.Reload Project
Set as StartUp Project
.Not fun.