You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法在Entity Framework Core中创建迁移的问题求助

问题描述

执行EF Core迁移创建命令时遇到以下问题:

  • 运行命令 dotnet ef migrations add InitialCreate --output-dir data\Migrations 报错:Entity Framework工具版本'8.0.10'低于运行时版本'9.0.0-rc.2.24474.1'
  • 无法解析GameStore.data.GameStoreContext所需的DbContextOptions服务,无法激活实例
  • VS Code集成终端无法识别sqlite3命令,但在CMD中可正常使用
相关配置文件

.csproj 文件

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

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0-rc.2.24474.1">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.0-rc.2.24474.1" />
    <PackageReference Include="MinimalApis.Extensions" Version="0.11.0" />
  </ItemGroup>

</Project>

GameStoreContext.cs 文件

using System;
using GameStore.Entities;
using Microsoft.EntityFrameworkCore;

namespace GameStore.data
{
    public class GameStoreContext(DbContextOptions<GameStoreContext> options) : DbContext(options)
    {

        // DbSets representing tables in your database
        public DbSet<Game> Games { get; set; }
        public DbSet<Genre> Genres { get; set; }
    }
}

appsettings.json 文件

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "GameStore": "Data Source=GameStore.db"
  }
}

内容的提问来源于stack exchange,提问作者Mohamad Umar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 04:07:37