Can't Add Migration in Visual Studio Code for EntityFrameworkCore

Viewed 5106

I'm trying to build a DotNetCore WebApi in Visual Studio Code with EntityFrameworkCore.

I've been reading a number of tutorials and I always get stuck at the point where it says:

Run Add-Migration InitialCreate

I get the following error:

The term 'add-migration' is not recognized as the name of a cmdlet, function, script file, or operable program

Other tutorials say I should run this command dotnet ef migrations add InitialCreate

Which gives me the error: No executable found matching command "dotnet-ef"

These are the references in my csproj:

<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3"/>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2"/>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="1.1.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.1.0-preview4-final"/>

How can I add a migration?

2 Answers

to make the "dotnet-ef" command available in Visual Studio Code,Install the dotnet ef tool by running the preceding command.

dotnet tool install --global dotnet-ef

Adding a migration:

dotnet ef migrations add MigrationName

try executing

dotnet ef database update
Related