You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Collation lost when changing type from varchar to text #3476
When changing a type of a column from varchar to text the previously set collation seems to be lost.
The migration adds a Alter Column statement specifying the same collation for both old and new.
My expected sql code would have been something like
ALTER TABLE address ALTER COLUMN tag TYPE text COLLATE case_insensitive;
which if done manually works and keeps the collation but this is not what is happening in the migration.
orginial Entity Configuration
builder.Property(address => address.Tag).HasMaxLength(50);
When removing the HasMaxLength(5) the below migration is created.
public class AddressEntity
{
public required string? Tag { get; set; }
}
migrationBuilder.AlterColumn<string>(
name: "tag",
table: "address",
type: "text",
nullable: true,
collation: "case_insensitive",
oldClrType: typeof(string),
oldType: "character varying(50)",
oldMaxLength: 50,
oldNullable: true,
oldCollation: "case_insensitive");
After this the collation for this column is null
Activity
Verdurakh commentedon Feb 27, 2025
Note that if I set the oldCollation = null it works as expected
Verdurakh commentedon Feb 28, 2025
seems to be from here
https://github.com/npgsql/efcore.pg/blob/main/src/EFCore.PG/Migrations/NpgsqlMigrationsSqlGenerator.cs
Line 459
Preserve collation when changing column type
roji commentedon Feb 28, 2025
Thanks @Verdurakh, have pushed a fix in #3476 and will backport to 9.0.4.
Preserve collation when changing column type (#3479)
Preserve collation when changing column type (#3479)
Preserve collation when changing column type (#3479)
Preserve collation when changing column type (#3479)
Preserve collation when changing column type (#3479)