Can't Add Migration in Visual Studio Code for EntityFrameworkCore

asp.net-core entity-framework-core visual-studio-code

Question

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?

1
2
7/19/2017 10:06:36 AM

Accepted Answer

To be able to use the command line CLI to manage migrations, you need to have the tools as part of your project. Make sure you have something like this in your project:

<ItemGroup>
    <DotNetCliToolReference 
        Include="Microsoft.EntityFrameworkCore.Tools.Dotnet" 
        Version="1.0.1" />
</ItemGroup>

Next from the command line, make sure you are in the same directory as the csproj file and run this:

dotnet ef migrations add InitialCreate
6
7/19/2017 10:52:49 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow