我正在尝试使用 EntityFrameworkCore 在 Visual Studio Code 中构建 DotNetCore WebApi。
我一直在阅读一些教程,但我总是卡在它说的地方:
运行 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"/>
如何添加迁移?
最佳答案
为了能够使用命令行 CLI 来管理迁移,您需要将这些工具作为项目的一部分。确保你的项目中有这样的东西:
<ItemGroup>
<DotNetCliToolReference
Include="Microsoft.EntityFrameworkCore.Tools.Dotnet"
Version="1.0.1" />
</ItemGroup>
接下来从命令行,确保您与
csproj
位于同一目录中。文件并运行这个:dotnet ef migrations add InitialCreate
关于asp.net-core - 无法在 Visual Studio Code 中为 EntityFrameworkCore 添加迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45187224/