Home: Run Add-Migration from NuGet package manager console, you get : The term 'Add-Migration' is not recognized

Created on 17 Jan 2017  路  10Comments  路  Source: NuGet/Home

from internal bug: 368394 & 372378 & 378413

REPRO STEPS

  1. Create a 1.0 Core Web Application
  2. F5
  3. Register yourself as a user (click Register in upper right, fill in name and password, Register)
  4. Add Movie.cs to the Models folder

聽聽聽 public class Movie
聽聽聽 {
聽聽聽聽聽聽聽 public int ID { get; set; }
聽聽聽聽聽聽聽 public string Title { get; set; }
聽聽聽聽聽聽聽 public DateTime ReleaseDate { get; set; }
聽聽聽聽聽聽聽 public string Genre { get; set; }
聽聽聽聽聽聽聽 public decimal Price { get; set; }
聽聽聽 }

  1. Add Controller - scaffold controller with EF / views
  2. Ctrl-F5, navigate to http://localhost:54365/Movies
  3. Run EF migrations
    Add-Migration AddMovies
    Update-Database

    ACTUAL
    EF fails for me in an unexpected way:

    PM> add-migration
    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.
    At line:1 char:1
  4. add-migration
  5. ~~~~~
    聽聽聽 + CategoryInfo聽聽聽聽聽聽聽聽聽 : ObjectNotFound: (add-migration:String) [], CommandNotFoundException
    聽聽聽 + FullyQualifiedErrorId : CommandNotFoundException

    PM>

    PM> update-database
    update-database : The term 'update-database' 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
  6. update-database
  7. ~~~
    聽聽聽 + CategoryInfo聽聽聽聽聽聽聽聽聽 : ObjectNotFound: (update-database:String) [], CommandNotFoundException
    聽聽聽 + FullyQualifiedErrorId : CommandNotFoundException
VS.PMConsole Investigate

Most helpful comment

hi all for this you have to go to tools-> nugetpackagemanager -> manage nuGut Package for solution
and install
Microsoft.AspNetCore.App
Microsoft.EntityFrameworkCore.Tools"
Microsoft.VisualStudio.Web.CodeGeneration.Design
then close vs and open it again .
reference
https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell

All 10 comments

@jainaashish has additional context here.

I think it's is due to ExecutionPolicy, Nuget can't execute the init.ps in entityframeworkcore.tool, if user log in VS as admin, nuget will set executionPolicy and run init.ps well

@zhili1208 - have you investigated default windows installations vs different VM environments to help find the cause of this?

the default windows powershell execution policy is restricted both on vm and real machine, but nuget will set executionPolicy to RemoteSigned, I tested xlab and azure vm, found out I can't repro it every time, looks like nuget can set executionPolicy correctly, but I hit this randomly, will look at it more

added new dupe bug number in first entry in this issue. 372378 - please read and confirm dupe. use that extra info (and/or the bug filer) to help reproduce the problem.

added new dupe in first entry: 378413

Feb 2018, VS2017 v15.5.6, and this problem is still alive and kicking.

However, what eventually fixed it for me was to go into VS2017, click on ToolsNuGet Package ManagerPackage Manager Settings, then, in the General tab, click on "Clear all NuGet Cache(s)". Then I quit VS2017, restarted VS2017, right-clicked on my Solution, and "Restore NuGet Packages".

After jumping through all of these hoops, the Add-Migration command was finally recognised.
(Sigh.)

all of this ^^^
Exact same error message.
Walked through MikeInSwitzerland's fix, but on the "Restore NuGet Packages" part, getting error message, "Error occurred while restoring Nuget packages: Access to path 'CUsers ... microsoft.codeanalysis.workspaces.common2.6.1' is denied."

hi all for this you have to go to tools-> nugetpackagemanager -> manage nuGut Package for solution
and install
Microsoft.AspNetCore.App
Microsoft.EntityFrameworkCore.Tools"
Microsoft.VisualStudio.Web.CodeGeneration.Design
then close vs and open it again .
reference
https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell

hi all for this you have to go to tools-> nugetpackagemanager -> manage nuGut Package for solution
and install
Microsoft.AspNetCore.App
Microsoft.EntityFrameworkCore.Tools"
Microsoft.VisualStudio.Web.CodeGeneration.Design
then close vs and open it again .
reference
https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell

already with have it but still same issue there.

http://prntscr.com/qb86n8

Please help me i got error when runing console Update-Database
Error Number:5123,State:1,Class:16 CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\Users\l-maninventory-management-codecanyon.mdf'. CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

http://prntscr.com/qb8ees

Was this page helpful?
0 / 5 - 0 ratings