无法使用Django和Docker在sqlite3中为初始数据设定种子

2024-04-30 23:48:58 发布

您现在位置:Python中文网/ 问答频道 /正文

更新:

我也在研究,但会继续添加我认为可能有用的链接

Migration and Seeding in Django

Providing initial data for models


这是我遇到的错误,因为我无法使用docker命令写入数据库(您将在下面看到)。这是我的假设


enter image description here


这是我的文件夹结构

enter image description here


docker compose.yml

version: "3"

services:
  django:
    build: ./api
    command: ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
    volumes:
      - ./api:/app
    ports:
      - "8000:8000"
  frontend:
    build: ./frontend
    volumes:
      - ./frontend:/app
      - /app/node_modules
    ports:
      - "3000:3000"

volumes:
  node-modules:

Dockerfile(在api文件夹内)

FROM python:3.7.6

WORKDIR /app
COPY requirements.txt /app
RUN pip3 install -r requirements.txt

COPY . .

# Run migrations and load seed data (using SQLite)
RUN python3 manage.py makemigrations
RUN python3 manage.py migrate
RUN python3 manage.py loaddata portal/fixtures/seed.yaml
RUN python3 manage.py loaddata scheduler/fixtures/seed.yaml

EXPOSE 8000
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]

我已经尝试了我能搜索到的大多数可能的项目,如果有人能在这里提供帮助,我将非常感激


Tags: anddockerrunpybuild文件夹apiapp
1条回答
网友
1楼 · 发布于 2024-04-30 23:48:58

在Docker Image CLI中运行命令

# Run migrations and load seed data (using SQLite)
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py loaddata portal/fixtures/seed.yaml
python3 manage.py loaddata scheduler/fixtures/seed.yaml

按顺序做

相关问题 更多 >