Docker compose run migrations on django web application + postgres db

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

Here is my docker-compose file

  • Docker in Jenkins pipeline fails to run due to invalid environment variable: =
  • Checking container connectivity with ping in a Calico network of Docker containers
  • Protecting docker filesystem access
  • Out of memory error in opencv3.0 which is running inside docker container
  • How to provide parameter to docker run with “oc new-app” in OpenShift?
  • Can't import own python module in Postgresql plpython function
  • 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.

  • Windows docker image build hangs on creating a directory
  • Docker installation issues on CentOS 7.1
  • Docker port mapping: 3-way handshake although nothing is listening
  • Building docker image that downloads large file fails with error
  • why docker container still can communicate with outside when i shutdown the iptables
  • Building on a docker image that sets user to an unprivileged user
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.