EF - Add Migration Error

Santhi Dhanuskodi 225 Reputation points
2023-07-27T11:41:56.8166667+00:00

hi,

I am trying to run Add-Migration command in PM.

But I am getting an error

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

I have all the EF packages installed. Cleared PM settings and restarted. restarted VS. Closed and reopened. All the solutions given on other sites are already tried out. But I am still getting this error.

User's image

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
726 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,400 questions
0 comments No comments
{count} votes

Accepted answer
  1. Zhi Lv - MSFT 32,106 Reputation points Microsoft Vendor
    2023-07-28T06:16:45.1466667+00:00

    Hi @Santhi Dhanuskodi

    Try to re-install the Microsoft.EntityFrameworkCore.Tools package and clear the NuGet Cache:

    uninstall Microsoft.EntityFrameworkCore.Tools package, then go to VS Tools -> Nuget Package Manger -> Package Manager Settings -> General Tab ->Clear All NuGet Cache(s) -> install the Microsoft.EntityFrameworkCore.Tools package ->Restart Visual Studio.

    If still not working, you can try to use the following commands to execute the migration:

    dotnet ef migrations add addPerson --context ApplicationDbContext --project Test
    dotnet ef database update --context ApplicationDbContext --project Test
    

    The result as below: User's image

    and

    User's image


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Dillion


2 additional answers

Sort by: Most helpful
  1. AgaveJoe 1,495 Reputation points
    2023-07-27T14:01:13.6433333+00:00

    Verify EF Core tools are installed.

    https://learn.microsoft.com/en-us/ef/core/cli/dotnet

    dotnet ef
    

    Install the tools globally.

    dotnet tool install --global dotnet-ef
    

    Also, make sure the correct default project is selected in the Program Manager Console.

    0 comments No comments

  2. Santhi Dhanuskodi 225 Reputation points
    2023-07-28T05:16:52.38+00:00

    hi

    I have verified package is installed. It is there and still I get the error.

    Below is the screenshot. Also installed EF as per ur suggestion, globally also.

    User's image

    0 comments No comments