So I am deploying django, postgress and nginx containers via docker-compose and I have an issue that I can't seem to figure out.
In order to resolve the following error in my Django app, I knew I just had to run a Django migration.
docker@postgres ERROR: relation "accounts_myprofile" does not exist
In an attempt to run migrations, I tried:
docker-compose run web python manage.py makemigrations
docker-compose run web python manage.py migrate
which returned the following:
Migrations for 'accounts':
accounts/migrations/0001_initial.py:
- Create model Entry
- Create model MyProfile
Running migrations:
No migrations to apply.
I was only able to successfully migrate from within the Django container, example:
docker exec -i -t 6dc97c6a305c /bin/bash
python manage.py makemigrations
python manage.py migrate
Although I have resolved the issue, I still don't understand why running the migrate via docker-compose run does not actually migrate anything. I'm hoping someone can maybe point me in the right direction on this.
Also, I don't know if this is a related issue or not, but when I run those docker-compose run web commands, they seem to be creating new containers that won't shutdown unless I manually stop them, docker-compose stop doesn't remove them.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a7bb3c7106d1 accounts_web "python manage.py che" 4 hours ago Restarting (0) 41 minutes ago 8000/tcp accounts_web_run_62
ee19ca6cdf49 accounts_web "python manage.py mig" 4 hours ago Restarting (0) 43 minutes ago 8000/tcp accounts_web_run_60
2d87ee35de3a accounts_web "python manage.py mak" 4 hours ago Restarting (0) 43 minutes ago 8000/tcp accounts_web_run_59
1c6143c13097 accounts_web "python manage.py mig" 4 hours ago Restarting (1) 44 minutes ago 8000/tcp accounts_web_run_58
6dc97c6a305c b1cb7debb103 "python manage.py run" 3 days ago Up 4 hours 8000/tcp accounts_web_1
Note: Docker-compose stop will properly stop the container at the bottom (as it should), but the other container that were created by docker-compose run web python manage.py migrate, will need to be manually stopped.
my docker-compose
web:
restart: always
build: ./web
expose:
- "8000"
links:
- postgres:postgres
volumes:
- /usr/src/app
- /usr/src/app/static
env_file: .env
environment:
DEBUG: 'true'
command: python manage.py runserver 0.0.0.0:8000
postgres:
restart: always
image: kartoza/postgis:9.4-2.1
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data/