1

Hi I am having issues running migrations on postgres db container from django.

Here is my docker-compose file

web:
  restart: always
  build: ./web
  expose:
    - "8000"
  links:
    - postgres:postgres
  volumes:
    - /usr/src/app
    - /usr/src/app/static
  env_file:
    - ./.env
  environment:
    - DEBUG=1
  command: /usr/local/bin/gunicorn mysite.wsgi:application -w 2 -b :8000

nginx:
  restart: always
  build: ./nginx/
  ports:
    - "80:80"
  volumes:
    - /www/static
  volumes_from:
    - web
  links:
    - web:web

postgres:
  restart: always
  build: ./postgres
  env_file: .env
  ports:
    - "5432:5432"
  volumes:
    - pgdata:/var/lib/postgresql/data/

The directory structure is below. enter image description here

The .env file defines the Postgres DB , user name and password

DB_NAME=test
DB_USER=test
DB_PASS=test!
DB_SERVICE=postgres
DB_PORT=5432
POSTGRES_USER=test
POSTGRES_DB=test
POSTGRES_PASSWORD=test!

When I run docker-compose build and docker-compose up -d nginx, postgres and web containers start. The postgres startup (default) creates the db, user and password. The django startup container installs requirements.txt and starts the django server (everything looks good).

On running makemigrations

docker-compose run web /usr/local/bin/python manage.py makemigrations polls I get the following output

Migrations for 'polls': 0001_initial.py: - Create model Choice - Create model Question - Add field question to choice

But when I run

docker-compose run web /usr/local/bin/python manage.py showmigrations polls the output is.

polls (no migrations)

on running docker-compose run web /usr/local/bin/python manage.py migrate --fake polls the output I see

Operations to perform: Apply all migrations: (none) Running migrations: No migrations to apply. Your models have changes that are not yet reflected in a migration, and so won't be applied. Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.

The tables are not created in postgres. What am I doing wrong ? Sorry for the long post but I wanted to put all the details here.

7
  • Do you only have one app or not?
    – Windsooon
    Sep 8, 2016 at 1:46
  • Have you configured Django to use postgresql in your settings.py? Sep 8, 2016 at 9:07
  • @KeenanLawrence Yes the Django is configured to use postgressql in settings.py .
    – rOrlig
    Sep 8, 2016 at 10:46
  • @Aison Yes there is only one app
    – rOrlig
    Sep 8, 2016 at 10:47
  • Which version of Django are you using? Sep 8, 2016 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.