gpt4 book ai didi

python - 部署到 Elastic Beanstalk 时运行 Django 迁移

转载 作者:太空狗 更新时间:2023-10-29 20:47:22 25 4
gpt4 key购买 nike

我在 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'

如何设置容器命令以在部署阶段用 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'

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

最佳答案

我不确定是否有特定的方式来回答是或否。但您可以将 --noinput 附加到您的容器命令。使用 --noinput 选项来禁止所有用户提示,例如“Are you sure?”确认消息。

try
command: 'source /opt/python/run/venv/bin/activate && python app/manage.py migrate --noinput'

或者..您可以通过 ssh 进入您的 elasticbean 实例并手动运行您的命令。这样您就可以更好地控制迁移。

  1. 使用 pip install awsebcli 安装 awsebcli
  2. 键入 eb ssh 你的环境名称
  3. 导航到您的 eb 实例应用程序目录:

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

  • 然后运行您的命令。

    ./manage.py 迁移

希望对你有帮助

关于python - 部署到 Elastic Beanstalk 时运行 Django 迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30950941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com