2

I'm using ASP.NET Core MVC and for some reason the package manager console in visual studio 2015 or the command prompt window will not recognize any Entity Framework commands like 'Enable-Migrations' 'dnx ef database update' etc..

I never had any issues with EF migrations in any other project where iv'e been using MVC 5 with Entity Framwork 6

I also tried restarting Visual Studio like many answers recommended but that didn't work for me.

The error message I get for enabling migrations is:

PM> Enable-migrations
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, verify that the path is correct and try again.
At line:1 char:1
+ Enable-migrations
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Enable-migrations:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
6
  • Please post the text of the error message, not a screenshot of it. My eyes aren't good enough to read that anymore. Commented Jun 20, 2016 at 15:30
  • @CraigW. Sorry about that, I added the text instead of screenshot. Commented Jun 20, 2016 at 15:45
  • The package might have not installed successfully. EF tools I believe are installed/enabled as part of the package install and if that didn't succeed correctly, you may not be able to get access to the commands. Commented Jun 24, 2016 at 14:29
  • @HarikrishnaMenonA I installed the latest Entity Framework from nuget so it's there, but still won't work. Commented Jul 4, 2016 at 5:22
  • Please, don't use MVC6 tags anymore. It's for a future version of ASP.NET MVC based on the old webstack (MVC5). ASP.NET Core is a complete new and incompatible, portable version based on .NET Core. Use asp.net-core-mvc and/or asp.net-core tags instead and your question is more likely to be found by people who can help you with the issue Commented Jul 8, 2016 at 12:04

1 Answer 1

1

First "dnx" command won't work if you installed the Entity Framewok Core or are using a Asp.Net Core application, you need to use the .Net Core CLI commands instead, and "enable-migrations" is not part of the commands list anymore.

So to add a migration to your project you need to use the following command in the command line opened from the root of your src folder:

dotnet ef migrations add {MigrationName}

There are many other commands, find out about them more by typing the following in the command line:

dotnet ef database --help

dotnet ef dbcontext --help 

dotnet ef migrations --help 

This is assuming that you already installed the EF Core and EF Core Tools in your project, you should have these two references in your project.json:

Under dependencies:

"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final" "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0"

Under tools:

"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"

All the previous information is related to the Entity Framework Core under a ASP.Net Core application. If you want to work with ASP.Net Core and the Entity Framework 6, it is also possible but that does require a few extra steps and a little plumbing to get it working seamlessly (kind of), specially if you want to make use of ASP.NEt Identity with EntityFramork 6. Let me know if that is what you are looking for or if what I mentioned applies to your current situation and if it solves things. I'll try my best.

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

Comments

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.