简体   繁体   中英

Issue with case insensitive collation with Postgres and Entity Framework core

I have tried to apply collation using model builder

modelBuilder.HasCollation("my_collation", locale: "en-u-ks-primary", provider: "icu", deterministic: false);

modelBuilder.UseCollation("my_collation");

The migration is created successfully, but on applying the migration it fails with this exception.

System.AggregateException: One or more errors occurred. (42P17: parameter "locale" must be specified)
 ---> Npgsql.PostgresException (0x80004005): 42P17: parameter "locale" must be specified
   at Npgsql.Internal.NpgsqlConnector.<ReadMessage>g__ReadMessageLong|215_0(NpgsqlConnector connector, Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)

 Exception data:
    Severity: ERROR
    SqlState: 42P17
    MessageText: parameter "locale" must be specified
    File: collationcmds.c
    Line: 244
    Routine: DefineCollation

I faced the same error today. I was using do.net 6, EF core 6, and Npgsql 6. Then I upgraded to do.net 7, EF core 7, Npgsql 7, and created a new migration then ran it and it was successful. So I think there may be some bug in Npgsql 6 that was fixed in 7.

The generated migration script that crates the ci collation:

            migrationBuilder.AlterDatabase()
                .Annotation("Npgsql:CollationDefinition:my_collation", "en-u-ks-primary,en-u-ks-primary,icu,False");

which I think the second parameter was corrected in Npgsql 7.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM