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

ASP.NET Core 5.0+React+MySQL集成IdentityServer配置报错求助

问题原因

你遇到的报错核心是 Pomelo.EntityFrameworkCore.MySql 3.0+版本取消了仅传入连接字符串的UseMySql重载方法,调用时必须显式指定MySQL服务器版本参数。

解决方案

步骤1:修改Startup.cs数据库配置代码

找到ConfigureServices方法中注册ApplicationDbContext的部分,修改为以下代码:

services.AddDbContext<ApplicationDbContext>(options =>
    options.UseMySql(
        Configuration.GetConnectionString("DefaultConnection"),
        // 自动探测本地MySQL版本,也可以手动指定,例如 new MySqlServerVersion(new Version(8, 0, 30))
        ServerVersion.AutoDetect(Configuration.GetConnectionString("DefaultConnection"))
    ));

步骤2:校验NuGet包版本兼容性

  • .NET 5 项目必须使用 5.x 版本的Pomelo.EntityFrameworkCore.MySql包,禁止使用6.0+版本
  • 所有Microsoft.AspNetCore.Identity、Microsoft.EntityFrameworkCore相关包的大版本必须和.NET版本一致,统一为5.x

步骤3:重新执行数据库迁移

删除之前生成的旧迁移文件,在包管理器控制台执行以下命令:

Remove-Migration
Add-Migration InitIdentitySchema
Update-Database

如果使用dotnet CLI,对应命令为:

dotnet ef migrations remove
dotnet ef migrations add InitIdentitySchema
dotnet ef database update

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 12:57:00