0
votes

I'm using entity framework 6 with MVC 5 and trying to enable migration in code first so that I can avoid data loss. But when type the command in package manager console, it throws following error:

PM> Enable-Migrations -ContextTypeName [ContextClassName] 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-Migrations -ContextTypeName [ContextClassName] + ~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Enable-Migration:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

I checked all duplicates but none of them worked in my case.

1
Does update-database work?Neil

1 Answers

3
votes

There are two possible scenarios here.

  1. Entity Framework is not installed or is installed incorrectly. If you do in fact have a reference to it, then first do:

    PM> Uninstall-Package EntityFramework -Force
    

    Then,

    PM> Install-Package EntityFramework
    

    Make sure to restart Visual Studio afterwards

  2. You're actually using Entity Framework Core or you've added Entity Framework to an ASP.NET Core project running on the full framework. In either of these cases, none of the Entity Framework package manager commands will be available. If you've installed EF Core by mistake, remove it and install EF6 instead. If you've got an ASP.NET Core project, you must add a console app or class library running on the full framework for the EF6 reference. You'll manage all your entities here, as well as run your package manager commands against this project. The reason for this is that the EF6 package manager commands are incompatible with ASP.NET Core, even if you're running on the full framework.