AWS App Runner部署Django后migrate执行失败求助
AWS App Runner执行Django Migrations失败问题
开发阶段通过makemigrations完成模型变更准备,将代码经Git部署到AWS App Runner实例后,需在实例数据库执行migrations,但所有尝试均导致服务更新失败并回滚。
已尝试的配置方案
方案1:包含post-build阶段的apprunner.yaml
version: 1.0 runtime: python3 build: commands: build: - pip install -r requirements/production.txt post-build: - source /var/app/venv/*/bin/activate - python manage.py migrate - deactivate run: runtime-version: 3.8.16 command: sh startup.sh network: port: 8000
方案2:移除post-build阶段的apprunner.yaml
保留上述配置中build阶段的pip install命令,移除post-build段,其余部分不变。
方案3:两种不同的startup.sh脚本
- 仅启动Gunicorn:
#!/bin/bash gunicorn config.wsgi:application
- 先执行migrate再启动Gunicorn:
#!/bin/bash python manage.py migrate && gunicorn config.wsgi:application
方案4:修改默认构建设置的启动命令
直接将启动命令设置为:python manage.py migrate && gunicorn config.wsgi:application
服务日志信息
12-01-2023 10:05:40 AM [AppRunner] Reading apprunner.yaml config file. 12-01-2023 10:05:40 AM [AppRunner] Successfully Validate configuration file. 12-01-2023 10:05:42 AM [AppRunner] Starting source code build. 12-01-2023 10:09:00 AM [AppRunner] Service update failed. For details, see service logs.
内容的提问来源于stack exchange,提问作者Getafix
相关产品推荐
相关产品推荐

