0
votes

Running into an issue when trying to set up my first migration. I am using EF 3.1.1, I have a layer for data which is SunshineCoffee.Data and another layer for Web which is SunshineCoffee.Web. The migrations will update a PostgreSQL database.

I run the following command:

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

and receive the following error:

**Could not execute because the specified command or file was not found. Possible reasons for this include:

  • You misspelled a built-in dotnet command.
  • You intended to execute a .NET Core program, but dotnet-ef does not exist.
  • You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.**

Here is my CSPROJ file:

<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

1

1 Answers

0
votes

The dotnet ef tool is no longer part of the .NET Core SDK that is why you are getting the above error. I have the same issue earlier and resolved by using the following:

To be able to manage migrations or scaffold a DbContext, install dotnet ef as a global tool typing the following command in terminal:

dotnet tool install --global dotnet-ef

For a specific version you can use the following command:

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

For more information regarding this read