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

.NET中PostgreSQL迁移报错42P17:需指定locale参数

.NET PostgreSQL数据库迁移报错42P17的解决办法

问题场景

在.NET环境配置PostgreSQL数据库迁移时,自动生成的迁移文件执行报错。执行的代码片段如下:

modelBuilder
    .HasAnnotation("Npgsql:CollationDefinition:insensitive_collation", "en-u-ks-primary,en-u-ks-primary,icu,")
    .HasAnnotation("Relational:MaxIdentifierLength", 63)
    .HasAnnotation("ProductVersion", "5.0.4")
    .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);

收到报错:42P17: parameter "locale" must be specified.

解决方法

问题根源是排序规则定义的格式错误,原字符串末尾多余的逗号导致PostgreSQL无法识别有效的locale参数。

修改方案1(推荐)

直接去掉末尾的逗号,将配置值修改为:

"en-u-ks-primary,en-u-ks-primary,icu"

修改方案2(明确指定locale)

如果需要显式声明locale参数,也可以调整为:

"en-u-ks-primary,en-u-ks-primary,icu,en_US"

原因说明

PostgreSQL中ICU排序规则的定义格式为[排序规则名],[LC_COLLATE],[LC_CTYPE],[提供器],[locale],原配置末尾的逗号使得最后一个参数(locale)为空,触发了参数缺失的报错。修正后参数格式符合要求,迁移即可正常执行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 01:04:59