【问题标题】:Issue creating initial migration .NET Core & EntityFramework & PostgreSQL创建初始迁移 .NET Core 和 Entity Framework 以及 PostgreSQL 的问题
【发布时间】:2020-11-18 11:44:39
【问题描述】:

尝试设置我的第一次迁移时遇到问题。我使用的是 EF 3.1.1,我有一个数据层 SunshineCoffee.Data 和另一个 Web 层 SunshineCoffee.Web。迁移将更新 PostgreSQL 数据库。

我运行以下命令:

dotnet ef --startup-project ../SunshineCoffee.Web migrations add InitialMigration

并收到以下错误:

**无法执行,因为找不到指定的命令或文件。 可能的原因包括:

  • 您拼错了内置的 dotnet 命令。
  • 您打算执行 .NET Core 程序,但 dotnet-ef 不存在。
  • 您打算运行全局工具,但在 PATH 上找不到具有此名称的 dotnet 前缀可执行文件。**

这是我的 CSPROJ 文件:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\SunshineCoffee.Data\SunshineCoffee.Data.csproj" />
  </ItemGroup>


</Project>

Snapshot of my Solution Explorer

【问题讨论】:

    标签: c# postgresql .net-core entity-framework-core


    【解决方案1】:

    dotnet ef 工具不再是 .NET Core SDK 的一部分,这就是您收到上述错误的原因。我之前有同样的问题,并通过使用以下方法解决:

    为了能够管理迁移或构建 DbContext,请将 dotnet ef 安装为全局工具,在终端中键入以下命令:

    dotnet tool install --global dotnet-ef
    

    对于特定版本,您可以使用以下命令:

    dotnet tool install --global dotnet-ef --version 3.1.4
    

    有关此read的更多信息

    【讨论】:

      猜你喜欢
      • 2021-07-26
      • 2021-04-07
      • 2020-07-10
      • 2018-11-05
      • 1970-01-01
      • 2021-01-21
      • 1970-01-01
      • 2019-02-12
      • 2017-10-27
      相关资源
      最近更新 更多