Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Collation ignored in migration #2028

Description

@jlareo

Describe the bug
When configuring the DbContext to use "utf8mb4" as the character set and "utf8mb4_unicode_ci" as the collation, the first migration generated in an EF Core project does not include the specified collation. As a result, the created database uses an unexpected collation.

Configuration in DbContext:

            builder.UseCollation("utf8mb4_unicode_ci");
            builder.HasCharSet("utf8mb4", DelegationModes.ApplyToDatabases);

Generated Migration

            migrationBuilder.AlterDatabase()
                .Annotation("MySql:CharSet", "utf8mb4");

I was expecting the following:

            migrationBuilder.AlterDatabase(
                collation: "utf8mb4_unicode_ci")
                .Annotation("MySql:CharSet", "utf8mb4");

Is this behaviour expected?

To Reproduce

  1. Add following configuration to DbContext: (OnModelCreating)
            builder.UseCollation("utf8mb4_unicode_ci");
            builder.HasCharSet("utf8mb4", DelegationModes.ApplyToDatabases);
  1. Create a new EF Core project without migrations.
  2. Add the first migration.
    The generated migration does not include the configured collation.

Expected behavior
When a collation is explicitly configured, it should be included in the generated migration.

Technical details (please complete the following information):

  • Database server version: [MariaDB 11.4.9]
  • Operating system: [Windows 11]
  • Pomelo.EntityFrameworkCore.MySql version: [9.0.0.efcore.9.0.0]
  • Other technical details: [ASP.NET Core]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions