Skip to content

Migration bug fix 2 - #4977

Merged
SchrodingersGat merged 3 commits into
inventree:masterfrom
SchrodingersGat:migration-bug-fix-2
Jun 6, 2023
Merged

SchrodingersGat merged 3 commits into
inventree:masterfrom
SchrodingersGat:migration-bug-fix-2

Conversation

@SchrodingersGat

Copy link
Copy Markdown
Member

Ref: #4898
Ref: #4961

This is a "new and improved" bug fix for migration shenanigans due to issues with #4989 and #4961

There is a small window for corrupted migrations to have already crept in, so this fix ensures that affected database columns are not created "twice".

- In inventree#4961 we did not notice that the migration files had been renamed
- There is still a chance that a production db (running from master) has a corrupted set of migrations
- Check if the duplicate columns already exist
- If they do, delete them first
@SchrodingersGat SchrodingersGat added bug Identifies a bug which needs to be addressed setup Relates to the InvenTree setup / installation process labels Jun 6, 2023
@SchrodingersGat SchrodingersGat added this to the 0.12.0 milestone Jun 6, 2023
@SchrodingersGat
SchrodingersGat merged commit f65281c into inventree:master Jun 6, 2023
@SchrodingersGat
SchrodingersGat deleted the migration-bug-fix-2 branch June 6, 2023 05:45
@miggland

miggland commented Jun 6, 2023

Copy link
Copy Markdown
Contributor

Tested this by starting a new instance based on commit c0dafe155fbaa872110bc53c5ce190b3fde53ada, stopping it, switching to a3150d9cb35bf24d4d27e1285180e1a9e75d0323, and running ìnvoke update`.

The migration fails, because of:

  File "/home/inventree/data/env/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.DuplicateColumn: column "checkbox" of relation "part_partparametertemplate" already exists

This occurs even if the check shows that the field does not exist:

PartParameterTemplate._meta.fields = (<django.db.models.fields.AutoField: id>, <django.db.models.fields.CharField: name>, <django.db.models.fields.CharField: units>, <django.db.models.fields.CharField: description>, <django.db.models.fields.json.JSONField: metadata>)
Column 'checkbox' does not exist (skipping)

The same goes for choices.

Suggested fix in #4979

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Identifies a bug which needs to be addressed setup Relates to the InvenTree setup / installation process

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants