-
Notifications
You must be signed in to change notification settings - Fork 95
Fix adding and dropping column with db_column_name in auto migration #983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Conversation
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
I have updated my comment with my analysis.
I hope this helps with the review.
@atkei That's very helpful, thanks 👍
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.
Uh oh!
There was an error while loading. Please reload this page.
Fix #945.
Analysis
Adding Column with
db_column_nameWhen adding a new column with
db_column_nameto an existing table, the forward migration succeeds, but a column withnameinstead ofdb_column_nameis created in the actual table.For example, if adding
agefield to theUsersclass and then running the forward migration, the created column name is notuser_agebutage.And more, backward migration after it fails with UndefinedColumnError because
db_column_namein the migration file does not match the column name in the DB.In my analysis, this is because the migration file is created as expected, but migration process create column with
nameinstead ofdb_column_name.This issue would be fixed by deleting the following line.
https://github.com/piccolo-orm/piccolo/blob/master/piccolo/query/methods/alter.py#L320
In my understanding, there is no problem to delete the line beause if
db_column_nameis None, the property returnsname.Dropping Column with
db_column_nameWhen dropping a column from an existing table, the forward migration fails.
For example, if removing
agefield from theUsersclass and then running the forward migration, it fails with UndefinedColumnError.In my analysis, this is because the migration file is created as expected, but migration process attempts to drop the column by specifing
nameinstead ofdb_column_name.This issue would be fixed by changing the argument of the following line to
column.db_column_nameorcolumn.https://github.com/piccolo-orm/piccolo/blob/master/piccolo/apps/migrations/auto/migration_manager.py#L670