[英]Error with Docker Compose Django and PostgreSql
I have a problem when I create any object in my django admin.我在 django 管理中创建任何对象时遇到问题。 It shows me this error:它向我展示了这个错误:
LINE 1: SELECT (1) AS "a" FROM "license_portal_client" WHERE
Here is my Dockerfile
:这是我的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
:这是我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:我的数据库settings.py
和我在已安装的应用程序中添加了我的应用程序:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': 'db',
'PORT': 5432,
}
}
And here is my models.py
:这是我的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
:还有我的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.尝试从 django 容器中运行 django migrate 命令并停止您可能拥有的任何现有数据库连接——就像运行开发服务器的web
容器一样。
# 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.