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.
This question is related to
entity-framework
migration
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 */
run as administrator vs =>> Open the project
-> On the Package manager Console
Enable-migration
add-migration migrationName
update-database
Make sure you are running Visual Studio as a administrator.
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
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!
Restarting Visual Studio with administrator privilege solved the issue for me.
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.
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
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.
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.
Just simply re-starting Visual Studio worked for me. No need to install packages, etc.
Enable-Migrations -EnableAutomaticMigrations
First "Install-Package EntityFramework -IncludePrerelease" and then Restarting Visual Studio as a Administrator worked for me together.
Check if the project is open in the Solution Explorer window.
This could be the cause of your problem.
Check the version of the Entity Framework.
if it is 6.3, downgrade it to 6.2 and it should work just fine
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>
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
In VS 2013, try to install the UPDATE 1(RC1) and the problem is resolved.
I tried all of the above suggestions but nothing worked for me then I updated Nuget Package Manager
and it worked..
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
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.
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.
Since I already had migrations folder, I restarted Visual Studio and ran Update-Database -verbose in package manager console. That worked for me
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
Source: Stackoverflow.com