Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The term 'add-migration' is not recognized as the name of a cmdlet

So randomly from one day to the next my migrations stopped working. I do add-migration and it says its not being recognized. I'm using PM since this is a asp.net mvc and was working the day before.

add-migration : The term 'add-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.

enter image description here

like image 479
Richard Jimenez Avatar asked Aug 10 '17 14:08

Richard Jimenez


People also ask

Why add migration is not recognized?

Add-Migration - The Term 'Add-Migration' Is Not Recognized After creating models and context class, we nomally add migration to initialize the database. The error occurs sometimes while adding migration in asp.net core, entity framework with code first approach because of some missing library.

Where is add migration command?

Open the Package Manager Console from Tools → Library Package Manager → Package Manager Console and then run the enable-migrations command (make sure that the default project is the project where your context class is).

How do I run an add migration in Visual Studio?

Adding a Migration So, firstly, you need to create a migration. Open the Package Manager Console from the menu Tools -> NuGet Package Manager -> Package Manager Console in Visual Studio and execute the following command to add a migration.


3 Answers

This isn't exactly the issue the OP is having, but for dotnet core at least, this can also be caused by not having the Microsoft.EntityFrameworkCore.Tools nuget package installed, which is used for the package manager commands in Visual Studio and command line.

like image 123
Warrick Avatar answered Nov 03 '22 17:11

Warrick


What I had to do...

1) Tools -> Nuget Package Manger -> Package Manager Settings

2) General Tab

3) Clear All NuGet Cache(s)

4) Restart Visual Studio

like image 27
Tyrone Moodley Avatar answered Nov 03 '22 18:11

Tyrone Moodley


I suspect that your default project needs to be set, as Kirk Larkin mentioned in the comments. Click the drop down list on default project and set it to which ever project you have entity framework installed on.

enter image description here

Also this link might help if your default project drop down list won't populate NuGet Package Manager Console Default Project dropdown is empty

Hope this helps! If not let me know and I'll remove the answer(I had to use an answer because I can't comment under 50 rep) Cheers!

like image 41
Chase Avatar answered Nov 03 '22 18:11

Chase