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

.NET Core 3.1执行EF迁移报错Keyword not supported: 'server'原因问询

报错根因

你遇到的报错核心是EF Core上下文加载的数据库驱动和连接字符串不匹配:

  • 从报错日志的Entity Framework Core 3.1.3 initialized 'MyDatabaseContext' using provider 'Microsoft.EntityFrameworkCore.Sqlite'可以看出,当前项目默认配置的是Sqlite数据库驱动
  • 你传入的连接字符串是Azure SQL Database(遵循SQL Server协议)的格式,Server属于SQL Server专属的连接字符串关键字,Sqlite驱动无法识别该关键字,因此抛出参数异常。
解决步骤
  1. 首先确认项目已安装和EF Core 3.1.3版本匹配的Microsoft.EntityFrameworkCore.SqlServer NuGet包
  2. 找到项目中MyDatabaseContext的注入配置代码,一般在Startup.cs文件中,将默认的Sqlite配置替换为SQL Server配置:
    将原有类似代码:
services.AddDbContext<MyDatabaseContext>(options =>
    options.UseSqlite(Configuration.GetConnectionString("MyDbConnection")));

修改为:

services.AddDbContext<MyDatabaseContext>(options =>
    options.UseSqlServer(Configuration.GetConnectionString("MyDbConnection")));
  1. 保存修改后重新执行dotnet ef database update命令,即可正常执行数据库迁移操作。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.06 21:15:02