Migrations: Allow nullable and default on a column rename #944
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.
This PR adds the possibility to, on a colmun renaming when writing a migration, precise if the colmun is nullable or not, and the default value.
Why?
Because if I want to rename a nullable and null by default table, I actually can't:
The code
generates the SQL (at least when using MySQL)
that results in
Because it tries to change a column where some values are actually NULL to a not null column.
How?
The best way for me to fix this issue is to make the migration fetch the table structure in the
__enter__, instead of usingFalsefor thenullableattribute of theColumnclass by default. It would also remove the need to precise the column's length each time, so that's probably the simplest way for devs to use this.Another okay option would be to make the
nullableattribute of theColumnclass optionnal andNoneby default; this way, on rename, it would simply not be mentionned (it isn't required anyway for renaming) and the generated SQL would simply beWhich is clearely better.
But I did neither. I looked at how it was working, and simply followed the way
lengthis implemented. This method is pretty lame to use because you need to precise each time if your column is nullable and what is the default when you're renaming it, but, well: