部署到Elastic Beanstalk时运行Django迁移

use*_*731 8 python django amazon-web-services

我在Elastic Beanstalk上设置了我的Django应用程序,并且最近对我希望现在应用于实时数据库的数据库进行了更改.我知道我需要将其设置为容器命令,并且在检查数据库后我可以看到迁移已经运行,但我无法弄清楚如何对迁移进行更多控制.例如,我只希望在必要时运行迁移,但根据我的理解,容器将在每个部署上运行迁移,假设命令仍在配置文件中列出.此外,在某些情况下,我将在迁移期间获得选项,例如:

Any objects realted to these content types by a foreign key will also be deleted.
Are you sure you want to delete these content types?
If you're unsure, answer 'no'
Run Code Online (Sandbox Code Playgroud)

如何yes在部署阶段设置容器命令以响应此操作?

这是我当前的配置文件

container_commands:
  01_migrate:
    command: 'source /opt/python/run/venv/bin/actiate && python app/manage.py makemigrations'
    command: 'source /opt/python/run/venv/bin/activate && python app/manage.py migrate'
Run Code Online (Sandbox Code Playgroud)

有没有办法将这两个命令设置为仅在必要时运行并响应我在迁移期间收到的是/否选项?

Far*_*orn 11

我不确定是否有一种特定的方式来回答是或否.但是你可以附加--noinput到你的容器命令.使用该--noinput选项可禁止所有用户提示,例如"您确定吗?"确认消息.

try
    command: 'source /opt/python/run/venv/bin/activate && python app/manage.py migrate --noinput'
Run Code Online (Sandbox Code Playgroud)

或者..您可以ssh到您的elasticbean实例并手动运行您的命令.然后,您将可以更好地控制迁移.

  1. 安装awsebcli pip install awsebcli
  2. 类型 eb ssh Your EnvironmentName
  3. 导航到您的eb实例应用程序目录:

  • sudo -s
  • source/opt/python/run/venv/bin/activate
  • source/opt/python/current/env
  • cd/opt/python/current/app

  • 然后运行你的命令.

    ./manage.py迁移

我希望这有帮助