python - Django migrate 不会在 Elastic Beanstalk 上创建任何迁移
问题描述
正如标题所说。这是我的.ebextestions/django.config
(当然不包括在内.gitignore
)
container_commands:
01_migrate:
command: "source /var/app/venv/*/bin/activate python3 manage.py migrate --noinput"
leader_only: true
02_collectstatic:
command: "source /var/app/venv/*/bin/activate python3 manage.py collectstatic --noinput"
03_createsu:
command: "source /var/app/venv/*/bin/activate python3 manage.py createsu"
leader_only: true
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: "myApp.settings"
PYTHONPATH: "/var/app/venv/staging-LQM1lest/bin:$PYTHONPATH"
aws:elasticbeanstalk:container:python:
WSGIPath: "myApp.wsgi:application"
aws:elasticbeanstalk:environment:proxy:staticfiles:
/static: static
packages:
yum:
git: []
python3-devel: []
mariadb-devel: []
setting.py
文件
# [...]
if 'RDS_HOSTNAME' in os.environ:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.environ['RDS_DB_NAME'],
'USER': os.environ['RDS_USERNAME'],
'PASSWORD': os.environ['RDS_PASSWORD'],
'HOST': os.environ['RDS_HOSTNAME'],
'PORT': os.environ['RDS_PORT'],
}
}
# [...]
cfn-init-cmd.log
文件
2020-10-24 19:06:58,897 P9954 [INFO] ************************************************************
2020-10-24 19:06:58,898 P9954 [INFO] ConfigSet Infra-EmbeddedPreBuild
2020-10-24 19:06:58,901 P9954 [INFO] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2020-10-24 19:06:58,901 P9954 [INFO] Config prebuild_0_myApp
2020-10-24 19:07:03,679 P10119 [INFO] ************************************************************
2020-10-24 19:07:03,679 P10119 [INFO] ConfigSet Infra-EmbeddedPostBuild
2020-10-24 19:07:03,682 P10119 [INFO] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2020-10-24 19:07:03,682 P10119 [INFO] Config postbuild_0_myApp
2020-10-24 19:07:03,690 P10119 [INFO] ============================================================
2020-10-24 19:07:03,690 P10119 [INFO] Test for Command 01_migrate <<== Test succeded
2020-10-24 19:07:03,694 P10119 [INFO] Completed successfully.
2020-10-24 19:07:03,694 P10119 [INFO] ============================================================
2020-10-24 19:07:03,694 P10119 [INFO] Command 01_migrate
2020-10-24 19:07:03,697 P10119 [INFO] Completed successfully. <<== Migration completed
2020-10-24 19:07:03,704 P10119 [INFO] ============================================================
2020-10-24 19:07:03,704 P10119 [INFO] Command 02_collectstatic
2020-10-24 19:07:03,708 P10119 [INFO] Completed successfully.
2020-10-24 19:07:03,715 P10119 [INFO] ============================================================
2020-10-24 19:07:03,715 P10119 [INFO] Test for Command 03_createsu
2020-10-24 19:07:03,718 P10119 [INFO] Completed successfully.
2020-10-24 19:07:03,719 P10119 [INFO] ============================================================
2020-10-24 19:07:03,719 P10119 [INFO] Command 03_createsu
2020-10-24 19:07:03,722 P10119 [INFO] Completed successfully.
当我打开时,xyz.elasticbeanstalk.com/admin/
我收到此消息:
Exception Value: (1146, "Table 'ebdb.django_site' doesn't exist")
我在本地连接到数据库,看到到目前为止还没有通过ython3 manage.py migrate user_auth --noinput
命令创建表。(我已经makemigrations
在本地运行并且migrations
文件夹包含在 git 中)
我将所有 RDS 变量设置为弹性 beanstalk 配置。数据库不是与EB一起创建的,而是单独创建的,然后将其连接到EB。
我还 ssh'ed 到 EB 环境并使用source /var/app/venv/*/bin/activate
. 然后我跑了python3 manage.py migrate --noinput
,得到了这个错误:
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
此错误的原因是 IMO,'RDS_HOSTNAME' in os.environ
返回False
,因此未配置数据库。
所以,我跑了/opt/elasticbeanstalk/bin/get-config environment
,我在列表中看到了所有带有 RDS 前缀的变量。
然后我python3
在同一个环境中运行来检查它的值,os.environ
并且只能看到'DJANGO_SETTINGS_MODULE'
可用,但没有 RDS 前缀变量。
我从过去 2 天开始一直在研究它,阅读了数千个相关的博客、线程、文档,最后放弃了 :(。如果需要,我会提供任何其他相关信息。
解决方案
推荐阅读
- java - 如何获取recyclerview位置数据并将其传递给android studio中的另一个活动
- java - SharedPreferences 在应用程序强制关闭最近的活动时被清除
- hyperledger-fabric - Orderer 在使用 Fabric CA 生成的证书引导 HLF 网络时退出
- python - 为什么即使在安装 tensorflow 之后,我也会在 Pycharm 中收到错误“ModuleNotFoundError: No module named 'tensorflow.python.client'”?
- opencl - OpenCL 将多个字符串读入程序存储器
- laravel - 如何制作像 markAsRead 这样可用于 laravel 通知的方法
- java - 在多模块maven项目中查找未解决的maven依赖项
- sql - 对多个 LIKE 字符串进行分组
- python - 基于多个条件的跨列聚合
- python - 迭代具有相同结构的熊猫数据帧的dict的最佳方法,以生成一个包含每个(行,列)元素总和的数据帧?