django-mongo数据库docker迁移设置

时间:2018-11-19 19:10:08

标签: django mongodb docker

SELECT REFNUM FROM
(
  SELECT *,
    ROW_NUMBER() OVER (PARTITION BY REFNUM ORDER BY REFNUM  ) AS sequenceCorrect,
    ROW_NUMBER() OVER (PARTITION BY REFNUM ORDER BY TSTAMP) AS sequenceActual
  FROM queries
)
  AS yourTableSequenced
WHERE
  sequenceCorrect <> sequenceActual
ORDER BY REFNUM

这是我的用于mongodb的Django的docker-compose文件。 我不明白在哪里写“ python manage.py migration”。当我在“ runserver”命令之前编写时,它不起作用。

1 个答案:

答案 0 :(得分:1)

通常,您不想在每次启动服务器时都运行迁移,为了使临时容器的概念更加重要,一个更好的解决方案看起来像

services:
  web:
    build: .
    image: your_project
    command: python manage.py runserver 0.0.0.0:8000
    ports:
      - "8000:8000"
    depends_on:
      - migration
      - db
  migration:
    image: your_project
    command: python manage.py migrate --noinput
    depends_on:
      - db

原始答案

假设您已经完成python manage.py makemigrations

使用"bash -c 'python manage.py migrate --no-input && python manage.py runserver 0.0.0.0:8000'"