We might get this error sometimes while running add-migration command.
Error:
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.
Details Error:
PM> Add-Migration 'Intialize Database'
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
+ Add-Migration 'Intialize Database'
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Add-Migration:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Solution
You need to install Microsoft.EntityFrameworkCore.Tools from niget in the project containing migration context. In your migration project (DAL or infrastructure based on your project).
Install-Package Microsoft.EntityFrameworkCore.Tools
You can also use this link to install the latest version: Nuget package link
Tips: Install latest stable version.
Alternatively, you can install with package manager as shown:
Right click on project.
Also install Microsoft.EntityFrameworkCore.SqlServer
Both packages need to install in migration project.
Also install Micorsoft.EntityFrameworkCore.Design in startup class project and migration project.
Sometimes, the error persists because of cache, so restarting Visual Studio can solve the issue without doing anything.