0

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.

2

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

great !! it worked the same way you told. thanks Chris

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.