我在 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'
有没有办法将这两个命令设置为仅在必要时运行并响应我在迁移期间收到的是/否选项?
我不确定是否有特定的方法来回答是或否。但你可以附加--noinput
到您的容器命令。使用--noinput
禁止所有用户提示的选项,例如“您确定吗?”确认消息。
try
command: 'source /opt/python/run/venv/bin/activate && python app/manage.py migrate --noinput'
或者..
您可以 ssh 进入您的 elasticbean 实例并手动运行命令。
然后您将可以更好地控制迁移。
- 安装 awsebcli
pip install awsebcli
- Type
eb ssh Your EnvironmentName
- 使用以下命令导航到您的 eb 实例应用程序目录:
- sudo -s
- 源 /opt/python/run/venv/bin/activate
- 源 /opt/python/current/env
cd /opt/python/当前/应用程序
-
然后运行你的命令。
./manage.py 迁移
我希望这有帮助
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)