Unset the default value if the given column definition is an integer … #5391
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.
Unset the default value if the given column definition is an integer and the default value is a string
Summary
This is kinda of an edge case that I found when working with Laravel migrations. I wanted to change a column type from VARCHAR(32) DEFAULT '' to INT and got the following malformed SQL expression from Doctrine\DBAL\Platforms\AbstractMySQLPlatform\getAlterTableSQL()
"ALTER TABLE location_details CHANGE location_id location_id INT DEFAULT NOT NULL"
Since the column's original default value was a string, in this case an empty one '', it got carried over to the ALTER statement. The fix I propose is to check if the new column type is an PhpIntegerMappingType and if its default value a string then unset the default, similar to what we already do with TextType and BlobType. After this fix, the resulting SQL statement should be the following:
"ALTER TABLE location_details CHANGE location_id location_id INT NOT NULL"