12

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

4
  • 2
    I'm suspicious that your Default project: dropdown is empty. It should be enabled so long as you have a project open, so try selecting the project with your EF stuff in it from there and then running Add-Migration again. Commented Aug 10, 2017 at 14:41
  • Thank you Kirk for reaching out. After reviewing the default project in the drop down its empty even though my project is open which shows in solution explorer... SO basically there is nothing selected in the default project. Commented Aug 10, 2017 at 14:55
  • How can I go about this to fix this? Commented Aug 10, 2017 at 15:00
  • @RichardJimenez Did you find a solution to this? On Visual Studio 2019(enterprise preview), I have the same issue. I've restarted Visual Studio several times, updated it to the latest preview 3.0 and also installed Visual Studio 2019 Enterprise and 2017 Enterprise. None of the Solutions in these Comments nor the answer itself Solves this problem. I'm actually getting I'm actually getting [this repo][1] from github [1]: github.com/csharpfritz/Quiltoni.PixelBot Commented Jul 2, 2019 at 5:17

10 Answers 10

65

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.

3
  • 2
    after installing "Microsoft.EntityFrameworkCore.Tools" I had to restart the Visual Studio then it worked
    – Ezra
    Commented Feb 5, 2020 at 7:22
  • 1
    Did not need to restart with VS2022 Commented Feb 14, 2022 at 1:40
  • 1
    I can confirm that restarting VS2022 solved this problem for me too. Closing and reopening the solution did not solve the problem.
    – Mort
    Commented Feb 25, 2023 at 19:30
12

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

0
3

I had this same problem, and simply closing the Package Manager Console, then restarting Visual Studio fixed it.

1

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!

10
  • Can you explain this code? add-migration "Locations" -StartupProjectName "ProjectA" -ProjectName "ProjectB" Commented Aug 10, 2017 at 16:13
  • It's not really code to start off, it's a command to manually add the migration. So you would type that into the package manager console. "Locations" is where the project lives, "StartupProjectName" would be which project you want to use as your startup project, then just list the projects you want to get the changes from. Sorry if this isn't very clear I've never had this problem with entity framework so I've never had to use this manual command. Another thing that wasn't mentioned is try saving everything restarting Visual Studio and if that doesn't work try restarting your whole PC
    – Chase
    Commented Aug 10, 2017 at 16:19
  • Also don't forget to accept the answer if this resolves your problem so it doesn't keep showing up as unanswered on the questions search.
    – Chase
    Commented Aug 10, 2017 at 16:23
  • So for location will I have to clarify c drive desktop etc? or just the folder name where the project lives? Which in my case is a folder called Projects in my documents. The project name is GigHub inside projects. Im still quit confuse sorry btw. Commented Aug 10, 2017 at 16:26
  • 1
    after running its still saying add-migration is not being recognized. 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. Commented Aug 10, 2017 at 16:28
1

Ok, also we get the same error when "add-migration", i try one solution which is update Package Manager by using follow step

  1. In Visual Studio, from the "Tools" menu choose the "Extensions and Updates" option.
  2. From the dialog that appears, expand the "Updates" node from the tree at the left side.
  3. Select the "Visual Studio Gallery" option from the tree.
  4. Finally, look for the Package Manager update in the list of updates at the right side of the dialog and click the "Update" button beside it.

it is approx 5 - 10 MB update, after update complete try Get-Help Add-Migration

0

Even simpler for me, just re-starting VS2017 fixed this. Not had it until I got VS2017 professional, so this may be an issue for others in the latest version.

0
  1. In the nuget console, check if you have a right project selected as default.
  2. Set this project as a startup project
0

I reinstalled Nuget package manager and it worked for me. Fist I uninstalled the previous version, 2.0.x, then installed version 2.8.x

0

If you are facing this issue in Visual Studio for Mac then simply re-install Nuget Package Manager Console extension. It will solve your problem

0

this worked for me. so, in your console where you see default project(dropdown), make sure your current project is selected and most importantly check that the package source(dropdown) is selected as nuget.org

Not the answer you're looking for? Browse other questions tagged or ask your own question.