Stack Exchange
Error with Docker Compose Django and PostgreSql
I have a problem when I create any object in my django admin. It shows me this error:
LINE 1: SELECT (1) AS "a" FROM "license_portal_client" WHERE

Here is my Dockerfile:
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/

Here is my docker-compose.yml:
version: '3'
    
services:
  db:
    image: postgres
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
  web:
    build: .
    command: python license_portal/manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db

My database settings.py and I have added my app on installed apps:
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'postgres',
        'USER': 'postgres',
        'PASSWORD': 'postgres',
        'HOST': 'db',
        'PORT': 5432,
    }
}

And here is my models.py:
from django.db import models

class Person(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30) 

And my admin.py:
from django.contrib import admin
from license_portal.models import Person

admin.site.register(Person)


This is likely due to your database not being migrated. Try running the django migrate command from within a django container and stop any existing database connections you may have -- like the web container running the development server.
# Stop all of the running containers to release all db connections
docker-compose stop

# Run the migrate command inside of the django container
docker-compose run web python license_portal/manage.py migrate

# Start all of the containers again to access your dev server
docker-compose up web

