2017-07-19 31 views
1

我正尝试在Visual Studio代码中使用EntityFrameworkCore构建DotNetCore WebApi。无法在Visual Studio代码中为EntityFrameworkCore添加迁移

我一直在读了一些教程,我一直在点卡住的地方说:

运行Add-Migration InitialCreate

我得到以下错误:

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

其他教程说我应该运行这个命令 dotnet ef migrations add InitialCreate

这给了我错误: No executable found matching command "dotnet-ef"

这些人是我的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"/> 

我如何添加一个迁移?

+0

你在与proj文件相同的目录中运行该命令? – DavidG

+0

no'dotnet-ef'但是'dotnet ef'另外,确保你正在从包含'project.json'的目录运行'dotnet ef' – tchelidze

+0

@tchelidze'dotnet ef'会调用'dotnet-ef',这是完美的正常。 – DavidG

回答

4

为了能够使用命令行CLI管理迁移,您需要将这些工具作为项目的一部分。请确保你有这样的事情在你的项目:

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

在命令行下,确保你是在同一个目录中csproj文件并运行此:

dotnet ef migrations add InitialCreate 
相关问题