Dzianis Talkachou
Dzianis Talkachou

Reputation: 436

How to make migrate Django with Docker

I have docker db and web containers. After command docker-compose up -d --build I have errors with not exists relations in DB. I really don't have tables in DB. I execute following command:

$ docker-compose exec web python manage.py migrate

And I have following output:

Operations to perform:
  Apply all migrations: admin, auth, autos, bot, contenttypes, sessions, sites
Running migrations:
  Applying contenttypes.0001_initial... OK
  ...

If I execute this command second time, then I get No migrations to apply., but I still don't have tables in DB.

Part of my docker-compose.yaml:

version: '3.3'

x-base: &base
  restart: unless-stopped
  build: .
  working_dir: /code/autotracker
  env_file:
    - .env

services:
  web:
    <<: *base
    command: gunicorn autotracker.wsgi -b :8001
    volumes:
      - "/static:/static"
    ports:
      - "8001:8001"
    depends_on:
      - db

  db:
    image: postgres
    restart: unless-stopped
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    env_file:
      - .env.db
    ports:
      - 5432

volumes:
  postgres_data:

Upvotes: 3

Views: 176

Answers (1)

R.A.M
R.A.M

Reputation: 102

try make migrate first. by :

docker-compose exec web python3 manage.py makemigrations

after that try migrate :

docker-compose exec web python manage.py migrate

and then after finish two top command try :

docker-compose up -d --build

Upvotes: 1

Related Questions