Repository navigation
Fix HasColumnType("boolean") generating invalid boolean(1) DDL - #471
Open
selvasmallive wants to merge 1 commit into
Open
selvasmallive wants to merge 1 commit into
selvasmallive wants to merge 1 commit into
Conversation
HasColumnType("boolean") on a bool property generated `boolean(1)`,
which MySQL rejects. The type mapping source had no entry for the
aliases, so the lookup fell back to the default bool mapping
(tinyint with size 1) and the size postfix was applied to the
configured store type name.
Register `bool` and `boolean` as bool mappings without a size.
See PomeloFoundation#2045.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Configuring a
boolproperty with theBOOLEANorBOOLstore type produces DDL the server rejects:Reported for Pomelo 8.0.3 in PomeloFoundation#2045. It reproduces unchanged on
masterhere (10.0.12, EF Core 10.0.12, MySQL 8.4.10) forboolean,BOOLEAN,boolandBOOL(checked withGenerateCreateScriptandEnsureCreated).Root cause
MySqlTypeMappingSourcehas no store type entry forboolorboolean. The lookup by store type name misses, falls through to the CLR type lookup and returns the defaultboolmapping, which istinyintwithsize: 1andStoreTypePostfix.Size. EF Core then applies the configured store type name to that mapping and keeps the size postfix, givingboolean(1).BOOLandBOOLEANare synonyms forTINYINT(1)and do not accept a display width.Change
Register
boolandbooleanas store types mapped to aMySqlBoolTypeMappingwithout a size postfix, next to the existingtinyint(1)/bit(1)registration. Four lines inMySqlTypeMappingSource.The configured name is preserved (
booleanstaysbooleanin the migration and in the DDL); the server stores the column astinyint(1).Tests
New
test/EFCore.MySql.Tests/Migrations/MySqlBooleanStoreTypeAliasTest.cs, 7 test cases:boolean/BOOLEAN/bool/BOOLunsuffixed;tinyint(1)) and explicittinyint(1)mappings are unchanged;booleanandboolcolumns is created on the server, seeded, read back and filtered.All 7 fail on
master(the fixture'sEnsureCreatedhits the syntax error) and pass with the change.Results on MySQL 8.4.10, Windows, .NET SDK 10.0.101:
EFCore.MySql.TestsEFCore.MySql.FunctionalTests, fullmaster)I have no MariaDB instance locally, so MariaDB coverage relies on CI here.
Compatibility
tinyint(1),bit(1)orbit, map exactly as before.HasColumnType("boolean")today could not have created that column through EF, since the generated DDL was invalid. For such a model the snapshot and the current model now both resolve toboolean, so I expect no spurious migration; I have not tested an upgrade of an existing migrations folder.ClrBoolean != MySqlBooleanType.Noneblock, so theNonesetting behaves as before.Fixes the fork's equivalent of PomeloFoundation#2045.
🤖 Generated with Claude Code