无法在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
相关产品推荐
相关产品推荐

