當(dāng)我在 django 管理中創(chuàng)建任何對(duì)象時(shí)遇到問(wèn)題。它向我顯示了這個(gè)錯(cuò)誤:LINE 1: SELECT (1) AS "a" FROM "license_portal_client" WHERE這是我的Dockerfile:FROM python:3ENV PYTHONUNBUFFERED 1RUN mkdir /codeWORKDIR /codeCOPY requirements.txt /code/RUN pip install -r requirements.txtCOPY . /code/這是我的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我的數(shù)據(jù)庫(kù)settings.py和我已將我的應(yīng)用程序添加到已安裝的應(yīng)用程序中:DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'postgres', 'USER': 'postgres', 'PASSWORD': 'postgres', 'HOST': 'db', 'PORT': 5432, }}這是我的models.py:from django.db import modelsclass Person(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) 還有我的admin.py:from django.contrib import adminfrom license_portal.models import Personadmin.site.register(Person)
1 回答

慕少森
TA貢獻(xiàn)2019條經(jīng)驗(yàn) 獲得超9個(gè)贊
這可能是由于您的數(shù)據(jù)庫(kù)未遷移。嘗試從 django 容器內(nèi)運(yùn)行 django migrate 命令,并停止您可能擁有的任何現(xiàn)有數(shù)據(jù)庫(kù)連接——例如web運(yùn)行開(kāi)發(fā)服務(wù)器的容器。
# 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
添加回答
舉報(bào)
0/150
提交
取消