During working with docker where I dockerised Django PostgreSQL, I've entered in such problems as when I change some model and migrate it, after entering to the page, it says there is no such relationship in the database. After some research, I found that problem can be due to creating every time new migration and deleting the old. How can I fix this problem?
Below you can see my configurations
docker-compose-prod.yml
services:
app:
volumes:
- static_data:/app/staticfiles
- media_data:/app/mediafiles
env_file:
- django.env
- words_az.env
- words_en.env
build:
context: .
ports:
- "8000:8000"
entrypoint: /app/script/entrypoint.sh
command: sh -c "python manage.py collectstatic --no-input &&
gunicorn --workers=3 --bind 0.0.0.0:8000 django.wsgi:application"
depends_on:
- db
nginx:
build: ./nginx
volumes:
- static_data:/app/staticfiles
- media_data:/app/mediafiles
ports:
- "80:80"
- "443:443"
depends_on:
- app
- flower
db:
image: postgres:14.0-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- db.env
ports:
- "5432:5432"
redis:
image: redis:alpine
ports:
- "6379:6379"
worker:
build:
context: .
command: celery -A django worker -l info
env_file:
- django.env
depends_on:
- db
- redis
- app
flower:
build: ./
command: celery -A django flower --basic_auth=$user:$password --address=0.0.0.0 --port=5555 --url-prefix=flower
env_file:
- django.env
ports:
- "5555:5555"
depends_on:
- redis
- worker
volumes:
postgres_data:
static_data:
media_data:
Dockerfile
FROM python:3.9-alpine
ENV PATH = "/script:${PATH}"
COPY ./requirements.txt /requirements.txt
RUN apk add --update --no-cache --virtual .tmp gcc g++ libc-dev linux-headers \
&& apk add --virtual build-deps gcc python3-dev musl-dev \
&& apk add postgresql \
&& apk add postgresql-dev \
&& pip install psycopg2 \
&& apk add jpeg-dev zlib-dev libjpeg \
&& pip install Pillow \
&& apk del build-deps
RUN pip install --upgrade pip
RUN pip install -r /requirements.txt
RUN apk del .tmp
RUN mkdir /app
COPY /src /app
RUN mkdir /app/staticfiles
COPY /script /app/script
RUN chmod +x /app/script/*
WORKDIR /app
COPY django.env /app
RUN adduser -D user
RUN chown -R user:user /app
RUN chown -R user:user /var
RUN chmod -R 755 /var/
RUN chmod +x script/entrypoint.sh
USER user
CMD ["/script/entrypoint.sh"]