我使用Elastic Beanstalk将django项目上传到了AWS。
我将迁移命令写入django.config,并从aws cosole将postgrest数据库实例添加到环境中。
问题在于,根据日志,迁移命令被正确调用,但是即使数据库实例是全新的,它也会记录“没有要应用的迁移”。如果我检查页面使用数据库对象,则会显示与数据库相关的错误。
当我选择一个带有Car对象的页面时,出现以下错误。
ProgrammingError at /
relation "cars_car" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "cars_car"
^
# .ebextensions/django.config
container_commands:
01_migrate:
command: 'source /opt/python/run/venv/bin/activate && python manage.py migrate --noinput'
leader_only: true
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: ebaugustsix/wsgi.py
# DB and debug settings from settings module
from .base import *
import os
DEBUG = True
if 'RDS_HOSTNAME' in os.environ:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'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'],
}
}
# migrations/0001_initial.py
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Car',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
],
),
]