Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make migrate Django with Docker

Tags:

docker

django

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:
like image 998
Dzianis Talkachou Avatar asked Dec 07 '25 03:12

Dzianis Talkachou


1 Answers

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
like image 153
R.A.M Avatar answered Dec 12 '25 14:12

R.A.M



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!