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.

By Rijwan Ansari

Research and Technology Lead | Software Architect | Full Stack .NET Expert | Tech Blogger | Community Speaker | Trainer | YouTuber. Follow me @ https://rijsat.com Md Rijwan Ansari is a high performing and technology consultant with 10 plus years of Software Development and Business Applications implementation using .NET Technologies, SharePoint, Power Platform, Data, AI, Azure and cognitive services. He is also a Microsoft Certified Trainer, C# Corner MVP, Microsoft Certified Data Analyst Associate, Microsoft Certified Azure Data Scientist Associate, CSM, CSPO, MCTS, MCP, with 15+ Microsoft Certifications. He is a research and technology lead in Tech One Global as well as leading Facebook community Cloud Experts Group and SharePoint User Group Nepal. He is a active contributor and speaker in c-sharpcorner.com community, C# Corner MVP and his rank at 20 among 3+ millions members. Additionally, he is knee to learn new technologies, write articles, love to contribute to the open-source community. Visit his blog RIJSAT.COM for extensive articles, courses, news, videos and issues resolution specially for developer and data engineer.

Leave a Reply

Your email address will not be published.