Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code Entity Framework Core Add-Migration not recognized

I've used yoman to generate an ASP.Net Core Web API application via the Visual Studio Code Editor. For reference, I followed this tutorial here

The API works fine. However, I am trying to use Entity Framework Core Migrations with SQL Server. When I type the following into the Visual Studio Code Terminal:

Add-Migration MyDbInitialMigration 

I get the following message:

'Add-Migration' is not recognized as an internal or external command, operable program or batch file. 

I have the Microsoft.EntityFrameworkCore.Tools: 1.1.0-preview4-final dependency installed. I did this using the .Net Core Project Manager (Nuget) extension.

In Visual Studio 2015 this command works fine from the Package Manager Console.

I assume that using Visual Studio Code's Terminal is the problem. But does anyone know how I can use EF Core Migrations from within the VS Code editor itself?

Thanks for any help.

Solution

Running the dotnet ef migrations add InitialCreate command yielded the following error:

No executable found matching command "dotnet-ef" 

To solve this I needed to install the following dependency, AND add it to the tools section:

Microsoft.EntityFrameworkCore.Tools.DotNet 
like image 652
GreenyMcDuff Avatar asked Jan 08 '17 19:01

GreenyMcDuff


People also ask

Why add migration is not working?

Add-Migration - The Term 'Add-Migration' Is Not Recognized After creating models and context class, we nomally add migration to initialize the database. The error occurs sometimes while adding migration in asp.net core, entity framework with code first approach because of some missing library.

How do I run a migration code in Visual Studio?

In VS Code, click the Extensions icon on the Activity bar to open the Extensions view. Enter Migration Toolkit for Applications in the Search field. Select the Migration Toolkit for Applications extension and click Install.


2 Answers

You need to add:

dotnet tool install --global dotnet-ef 
like image 36
Rafael Almeida Avatar answered Sep 16 '22 15:09

Rafael Almeida


The correct format to add a new migration is dotnet ef migrations add yourMigrationName

and to update database is dotnet ef database update

like image 82
Dronacharya Avatar answered Sep 18 '22 15:09

Dronacharya