Home > Blockchain >  EF Core : migration failed, prompting that there is no TOOLS package
EF Core : migration failed, prompting that there is no TOOLS package

Time:02-16

In my ASP.NET Core 3.1 project, I am using EF Core for code migration. But when I use the add-migration MyProject command to operate, I get an error.

Your startup project 'MyProject' doesn't reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.

But I'm sure I downloaded the Entity Framework Core Tools package, I hope you can give me some advice, thank you.

CodePudding user response:

Can you show all your EFCORE dependencies?

I have a successful case of migration here, you can refer to:

Model:

public class TestModel
{


    [Key]
    public int Id { get; set; }

    public string Name { get; set; }

    public string pwd { get; set; }
}

DBContext:

 public class TestContext: DbContext
    {
        public TestContext(DbContextOptions<TestContext> options) : base(options) { }
        public DbSet<TestModel> Users { get; set; }
    }

appsettings.json:

  "ConnectionStrings": {
    "DefaultConnection": "your db"
  }

Startup.cs:

 public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext<TestContext>(options =>
        options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
            services.AddControllersWithViews();
        }

Here are the required dependencies:

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

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

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.14">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.14" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.14">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>

Migration :

enter image description here

  • Related