1

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 to INSTALLED_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?

Axel
  • 1,415
  • 1
  • 16
  • 40

2 Answers2

1

I had the same issues when using version control to submit changes to another environment.

What probably happens is that django believes it already made the migration, because of the information that is being passed along when you push those changes. What you need to do is to correct that behavior manually deleting those migrations or, if you don't need to keep information yet, force the migration from the beginning.

You may want to read the docs for future use, and I used the answers in this questions to solve the same issue.

Cote
  • 36
  • 1
  • 4
  • Hi Cote, thanks for your answer. I don't commit any files from the migrations folder except `__init__.py` to the repository. Where else is this information stored? – Axel Mar 12 '22 at 08:25
0

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.

Axel
  • 1,415
  • 1
  • 16
  • 40