Skip to content

HasColumnType("boolean") generates invalid boolean(1) in migrations #2045

Description

@polar-slon

HasColumnType("boolean") generates invalid boolean(1) in migrations

Description

When configuring a bool property with:

builder.Property(e => e.Flag)
    .HasColumnType("boolean");

the model snapshot correctly stores the configured column type as boolean:

b.Property<bool>("Flag")
    .HasAnnotation("Relational:ColumnType", "boolean");

However, the generated migration unexpectedly changes the column type to boolean(1):

Flag = table.Column<bool>(
    type: "boolean(1)",
    nullable: false)

The resulting SQL contains:

Flag boolean(1) NOT NULL

which is rejected by MySQL with:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(1) NOT NULL'

Expected behavior

The generated migration should preserve the explicitly configured store type:

type: "boolean"

and generate SQL:

Flag BOOLEAN NOT NULL

Alternatively, if Pomelo intentionally normalizes the alias, it could generate:

type: "tinyint(1)"

and corresponding SQL:

Flag TINYINT(1) NOT NULL

Both are valid.

boolean(1) is not valid MySQL syntax.

Investigation

While debugging EF Core migrations, I found that:

  • the model metadata contains the configured value boolean;
  • the model snapshot also contains boolean;
  • by the time MigrationsModelDiffer.Initialize(...) is called, the resolved StoreType is already boolean(1).

This suggests that the column type is being transformed before migration operations are created.

Environment

  • Pomelo.EntityFrameworkCore.MySql 8.0.3
  • Microsoft.EntityFrameworkCore 8.0.29
  • Microsoft.EntityFrameworkCore.Relational 8.0.29
  • Microsoft.EntityFrameworkCore.Design 8.0.29

Reproduction

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<TestEntity>()
        .Property(e => e.Flag)
        .HasColumnType("boolean");
}

Create a migration:

dotnet ef migrations add Initial

Observe that the generated migration contains:

type: "boolean(1)"

instead of:

type: "boolean"

Additional information

The issue only occurs when explicitly configuring the store type to boolean.

Without .HasColumnType("boolean"), Pomelo correctly generates tinyint(1).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions