Issue
I am trying to change some field names of Django models, but for some reasons Django does not want to see my migrations. I made sure the following things are properly set up:
myApp.apps.MyAppConfig
is added toINSTALLED_APPS
in settings.py- A migration folder with an empty
__init__.py
is present in my app folder - In myApp folder, I also have an empty
__init__.py
The whole procedure works just fine locally with a SQLite database and I can change field names and run python manage.py makemigrations
and python manage.py migrate
to migrate the database. However in production where I use Docker Compose for orchestration and Postgres as database only the first migration works fine. Afterwards when I change any model field name and try to run docker-compose exec projectname django-admin makemigrations
or docker-compose exec projectname python manage.py makemigrations
or add the app name behind these commands nothing helps.
Then Postgres can't handle the request, because it doesn't know the new field name:
2022-03-11 14:40:22.136 UTC [81] ERROR: column model_name.new_field_name does not exist at character 357
What am I missing here? How can I get Django to migrate?
Solution
At the end I was able to solve this issue by adding a Docker volume for the migrations folder. I believe a lot of times people put their entire code in a persistent volume, which would've also prevented this issue. However at least everything that needs to be persistent (obviously) needs a persistent volume.
Answered By - Axel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.