Package Manager Console Enable-Migrations CommandNotFoundException only in a specific VS project
Entity FrameworkMigrationEntity Framework Problem Overview
I tried to run the command 'Enable-Migrations' in a new project and I got the message:
PM> Enable-Migrations
The term 'Enable-Migrations' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verif
y that the path is correct and try again.
At line:1 char:18
+ Enable-Migrations <<<<
+ CategoryInfo : ObjectNotFound: (Enable-Migrations:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
But in all other projects the command runs just fine.
Why is this happening?
BTW, I'm using VS2010 Professional SP1
EDIT: I reinstalled with the commmand: Install-Package EntityFramework -IncludePrerelease and the problem went away.
Entity Framework Solutions
Solution 1 - Entity Framework
I reinstalled with the commmand: Install-Package EntityFramework -IncludePrerelease
and the problem went away.
Solution 2 - Entity Framework
Just simply re-starting Visual Studio worked for me. No need to install packages, etc.
Solution 3 - Entity Framework
This issue is occurring because we don't have Entity Framework installed. Please install Entity Framework using the below command.
Install-Package EntityFramework -IncludePrerelease
Once installed, choose the project in the package manger console default project drop down.
Make sure at least one class in your project inherits from data context, otherwise use the below class:
public class MyDbContext : DbContext
{
public MyDbContext()
{
}
}
If we don't do this we will get another error:
No context type was found in the assembly
After completing these things you can run
enable-migrations
Solution 4 - Entity Framework
I had the same issue with VS 2019 Preview, .Net Core, and EntityFramework Core.
Turns out I had to install via NuGet Microsoft.EntityFrameworkCore.Tools
and Microsoft.EntityFrameworkCore.Design
. Once that was done, it worked like a charm.
Solution 5 - Entity Framework
Restarting Visual Studio with administrator privilege solved the issue for me.
Solution 6 - Entity Framework
Make sure you are running Visual Studio as a administrator.
Solution 7 - Entity Framework
First "Install-Package EntityFramework -IncludePrerelease" and then Restarting Visual Studio as a Administrator worked for me together.
Solution 8 - Entity Framework
I had the same issue and I tried most of the solution provided by other folks but it worked for me with below steps. I have VS 2017.
Steps:
Install-Package EntityFramework -IncludePrerelease
then create a class as
public class MyDBContext : DbContext { public MyDBContext() { } }
and at the last execute
Enable-Migrations -EnableAutomaticMigrations
What didn't work for me:
: Restarting VS.
: only "Enable-Migrations" command, which is without -EnableAutomaticMigrations.
: restoring or updating Nuget Package Manager.
My original error in the beginning was
/* The term 'enable-migration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.At line:1 char:1
- enable-migration
-
+ CategoryInfo : ObjectNotFound: (enable-migration:String) [], CommandNotFoundException
*/
Solution 9 - Entity Framework
I just had the same problem in asp.net core VS2019
This solved it:
Install-Package Microsoft.EntityFrameworkCoreInstall-Package
Install-Package Microsoft.EntityFrameworkCore.Tools
Don't forget to set default project in Package Manager Console to your database project in case it differs.
While executing the migrations the default project also seems to play a role. At a later step it helped to install this to my main startup project (not the EF database project):
Install-Package Microsoft.EntityFrameworkCore.Design
Solution 10 - Entity Framework
In Visual Studio 2012 I had the same error. Had to uninstall NuGet (Tools > Extensions and Updates > Installed > All: NuGet Package Manager: Uninstall button). Then closed Visual Studio. Then reopened Visual Studio and reinstalled NuGet (Tools > Extensions and Updates > Online > Visual Studio Gallery: NuGet Package Manager: Download button). Then in following windows: click Install button, then click close button. Then close and reopen Visual Studio.
Solution 11 - Entity Framework
What fixed this symptom for me (VS2013) is uninstalling then reinstalling the EF package with Nuget. The difference in the csproj file changed this...
<Reference Include="EntityFramework">
<HintPath>..\packages\EntityFramework.6.1.1\lib\net45\EntityFramework.dll</HintPath>
</Reference>
...into this...
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\EntityFramework.6.1.1\lib\net45\EntityFramework.dll</HintPath>
</Reference>
I don't fully understand why yet, but it worked at least.
Solution 12 - Entity Framework
In .NET Core, I was able to reach the same resolution as described in the accepted answer, by entering the following in package manager console:
Install-Package EntityFramework.Core -Pre
Solution 13 - Entity Framework
Enable-Migrations -EnableAutomaticMigrations
Solution 14 - Entity Framework
run as administrator vs =>> Open the project
-> On the Package manager Console
Enable-migration
add-migration migrationName
update-database
Solution 15 - Entity Framework
I had the same problem and I found that it is because of some characters in project path like [ or ] I correct the project path and it worked fine!
Solution 16 - Entity Framework
Since I already had migrations folder, I restarted Visual Studio and ran Update-Database -verbose in package manager console. That worked for me
Solution 17 - Entity Framework
I tried all of the above suggestions but nothing worked for me then I updated Nuget Package Manager
and it worked..
Solution 18 - Entity Framework
-
Install Entity framework to the current project using the below command: PM> Install-Package EntityFramework -IncludePrerelease
-
Add a class "MyDBContext" in the Model folder as given below:
public class MyDBContext : DbContext { public MyDBContext() { } }
-
Now enable migrations for the current project with the below command: PM> enable-migrations
Solution 19 - Entity Framework
In VS 2013, try to install the UPDATE 1(RC1) and the problem is resolved.
Solution 20 - Entity Framework
I had multiple projects in the solution, but I had the correct Default Project set, so I thought it should work.
In the end, I had to add the -StartupProject MyProjectName
option to the command
Solution 21 - Entity Framework
None of these solutions worked for me. My solution was to delete packages/EntityFramework.6.1.3
and Restore NuGet Packages
I noticed that packages/EntityFramework.6.1.3/tools/EntityFramework.psd1
was missing, so this was a likely cause. How it got removed in the first place though I have no clue.
Solution 22 - Entity Framework
Check if config section "entityFramework" exists and described in your .config file
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/></configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
Solution 23 - Entity Framework
Check the version of the Entity Framework.
if it is 6.3, downgrade it to 6.2 and it should work just fine
Solution 24 - Entity Framework
if you create an MVC Web project You should select Authentication when creating the project . by defaults is not selected.
Solution 25 - Entity Framework
downgrade to 6.2 helped me.
.NET Framework version 4.6.1
Project in old format(non .NET Standard)
Visual Studio should be open with Admin rights for initial migration.
I guess EF with version above 6.2 require latest .NET Framework.
Solution 26 - Entity Framework
Check if the project is open in the Solution Explorer window.
This could be the cause of your problem.