Nisha Patel
Problem
I'm working on a Django Project that currently uses the third-party app Oscar. We're in the process of migrating away from Oscar, to a custom-built shop, and for this, we want to get rid of a bunch of old files, models, and of course the actual third-party dependencies. However, I am having a hard time doing this because the migration files keep throwing up errors.
The situation is that we have first-party models that depend on Oscar's models. For example:
This means we have a migration file that contains the code to create this table:
The product field from this Executable needs to be removed, so I removed the field from the model and created a new migration.
Now I want to remove all the Oscar apps from my INSTALLED_APPS list, but this is causing a whole lot of headaches because when I want to create or run any migration, I get this error:
I've tried to simply remove this field from the initial migration file, but then in the next migration (where this field is actually being removed from the model), I get a key error:
So it seems that I have to keep Oscar installed and part of INSTALLED_APPS forever because the initial migration uses this info? But this first migration is applied already, so it's kind of annoying that the initial migration needs to be valid for the next one to run.
Solution
I've got a very similar situation in my project. I've tried squashing the migrations, but have run into issues with circular dependencies which I have yet to resolve...
Having said this, you might want to try squashing the migrations (see
>https://docs.djangoproject.com/en/4.2/topics/migrations/#squashing-migrations), as that would solve your issue - you would be able to delete the old migrations once your production deployments are updated to the point of these squashed migrations, and then you would be able to delete the app from your INSTALLED_APPS once all references to it are removed from your project and its migrations.
In short, you run ./manage.py squashmigrations with the app and migration number you want to squash up to, and Django will try to optimize the migrations by removing fields that were added and then removed in later migrations, among other things.
Answered by: >Raddish IoW
Credit: >StackOverflow
Blog Links:
>How to manage the Text in the container in Django?
>Fix webapp stops working issue in Django- Python webapp
>Creating a form in Django to upload a picture from the website
>Sending Audio file from Django to Vue
>How to keep all query parameters intact when changing page in Django?
>Solved: TaskList View in Django
>Implement nested serializers in the Django rest framework
>How to filter events by month in Django?
>Sorting the restframework in Django
>Ways to access instances of models in view in order to save both forms at once in Django
>What makes index.html have such kind of name in Django?
>Fix Module Not Found during Deployment- Django
>Creating a Django with existing directories, files, etc.?
>How to Read a CSV file with PHP using cURL?