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:
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:
and generate SQL:
Alternatively, if Pomelo intentionally normalizes the alias, it could generate:
and corresponding SQL:
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:
instead of:
Additional information
The issue only occurs when explicitly configuring the store type to boolean.
Without .HasColumnType("boolean"), Pomelo correctly generates tinyint(1).
HasColumnType("boolean")generates invalidboolean(1)in migrationsDescription
When configuring a
boolproperty with:the model snapshot correctly stores the configured column type as
boolean:However, the generated migration unexpectedly changes the column type to
boolean(1):The resulting SQL contains:
which is rejected by MySQL with:
Expected behavior
The generated migration should preserve the explicitly configured store type:
and generate SQL:
Alternatively, if Pomelo intentionally normalizes the alias, it could generate:
and corresponding SQL:
Both are valid.
boolean(1)is not valid MySQL syntax.Investigation
While debugging EF Core migrations, I found that:
boolean;boolean;MigrationsModelDiffer.Initialize(...)is called, the resolvedStoreTypeis alreadyboolean(1).This suggests that the column type is being transformed before migration operations are created.
Environment
Reproduction
Create a migration:
Observe that the generated migration contains:
instead of:
Additional information
The issue only occurs when explicitly configuring the store type to
boolean.Without
.HasColumnType("boolean"), Pomelo correctly generatestinyint(1).