Repository navigation
Conversation
5dd6f18 renamed the pack_size field of SupplierPart to pack_quantity, but this migration was missed in the change. Trying to migrate from a DB older than two weeks ago therefore fails.
|
@mattbnz great catch, thanks for providing this :) |
|
@mattbnz I'd like to understand this a little bit better; changes to data migrations can cause lots of headaches! The migration you are changing, However the migration which added the In your setup, can you please run I think that the better approach here is to ensure that the migrations are run in the correct order |
|
Trying to run Running the showmirgations command in the old environment (running on a very old June 2022 git checkout from 9b4e443) that I'm trying to upgrade from shows that company is up to Then I'm copying that database across to a new environment against the current git head, which gives the above error when trying to run showmigrations. Running update shows that the company migrations are indeed being completely applied before the stock migrations are applied - from my niave interpretation of the output it looks like it's going through the models in alphabetical order and applying all outstanding migrations for each model before proceeding to the next one, it's not applying migrations in date order as you might be expecting... Full output at https://pastebin.pl/view/406538b9 |
|
Given the current excitement we are having over in #4987 due to a bad patch on a migration file, I want to ensure this is done perfectly Can you please try the following steps:
These steps should ensure that Please let me know how you go with this! |
|
No, I still get the original error. Thinking about this a bit more after a nights sleep, I think that makes sense - the issue is not so much the order the migrations are being run in, but the fact that a migration (regardless of what order it is running in) is trying to access an attribute on a model that no longer exists in the codebase that is being run... Put another way, the dependency is not on the data in the database (which migration ordering can solve), but on the code itself. Any attempt to execute the stock.0094_auto_20230220_0025 migration run in a codebase synced past 5dd6f18 is going to fail, because the codebase no longer contains SupplierPart.pack_size - so the migration cannot try and access that field regardless of database state/migration execution order. Basically by removing pack_size from the model, 5dd6f18 creates a situation where migrations that reference it must have been executed prior to that commit, or they will now fail. Presumably this is an inherent limitation on migrations and removing fields... A quick search leads to https://code.djangoproject.com/ticket/23861 where Django itself seemed to hit this case, and whcih resulted in the following being added: https://docs.djangoproject.com/en/4.2/topics/migrations/#considerations-when-removing-model-fields So I think you either need to accept the change to update the code of the migration (I agree risky, I haven't fully tested it in all scenarios), or ideally not remove the field and instead use the system_check_removed_details method to remove it instead of actually removing it, but even that seems like a lot of effort to revise at this point. I don't envy the situation sorry! FWIW, I'm past this now and not blocked, was just sending the PR to help others who might also be caught, but I guess up to you if the trade-offs are worth it or not, how common is it for InvenTree users to be a whole year behind like I was... |
- Ensure stock.0094 runs before company.0059 - Ref inventree#4984 - Ideally addresses historical migration issues
- Ensure stock.0094 runs before company.0059 - Ref #4984 - Ideally addresses historical migration issues
|
I think this has been addressed in #5027 so closing this one out. |
5dd6f18 renamed the pack_size field of SupplierPart to pack_quantity, but this migration was missed in the change. Trying to migrate from a DB older than two weeks ago therefore fails.