0

getting this error while migrate cmd (docker-compose exec web python manage.py migrate) previously tried all solutions available on stack-overflow. following Django for professionals book .

#docker-compose.yml#

services:
  web:
    build: .
    command: python /code/manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - 8000:8000
    depends_on:
      - db
  db:
    image: postgres
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    ports: 
      - 5432:5432
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres

volumes:
  postgres_data:

#dockerfile#

FROM python:3.9.6

#set environment variables

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

#set work directory
WORKDIR /code

#install dependencies
COPY Pipfile Pipfile.lock /code/
RUN pip install pipenv && pipenv install --system

# Copy project
COPY . /code/

#setting.py#

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'postgres',
        'USER': 'postgres',
        'PASSWORD': 'postgres',
        'HOST': 'db',
        'PORT': 5432
    }

}```
  • Nothing you show here tries to run migrations. What's the actual command you're running, and where are you running it from? Also see [How do you perform Django database migrations when using Docker-Compose?](https://stackoverflow.com/questions/33992867/how-do-you-perform-django-database-migrations-when-using-docker-compose) – David Maze Jul 20 '22 at 10:17
  • running ```docker-compose exec python manage.py makemigration``` – Aman Choudhary Jul 20 '22 at 15:52
  • running ```docker-compose exec python manage.py makemigration``` /usr/local/lib/python3.9/site-packages/django/core/management/commands/makemigrations.py:121: RuntimeWarning: Got an error checking a consistent migration history performed for database connection 'default': could not translate host name "db" to address: Temporary failure in name resolution warnings.warn( Migrations for 'users': users/migrations/0001_initial.py - Create model CustomUser from that i'm getting this – Aman Choudhary Jul 20 '22 at 15:52
  • ```docker-compose exec python manage.py migrate``` i'm getting the the above error. – Aman Choudhary Jul 20 '22 at 15:54

0 Answers0