适用于EC2而非EB上应用程序的AWS MySQL的Django DATABASE设置

时间:2019-01-23 12:05:08

标签: python amazon-ec2 database-migration amazon-rds makemigrations

我正在将EC2内部部署Django应用程序(不是EB,这不是我的用例),我正在尝试根据AWS文档在settings.py中配置数据库设置,但是我得到了关键错误,但我担心可能不是那么简单。

我遵守以下准则:

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-rds.html

settings.py看起来像这样:

DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': os.environ['babies'],
            'USER': os.environ['admin'],
            'PASSWORD': os.environ['adminpass'],
            'HOST': os.environ['instance.xxxxxx.us-east-1.rds.amazonaws.com'],
            'PORT': os.environ['3306'],
        }

    }

当我运行“ makemigrations”时出现错误:

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/home/nadeem/PycharmProjects/genesis01/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/nadeem/PycharmProjects/genesis01/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 325, in execute
settings.INSTALLED_APPS
  File "/home/nadeem/PycharmProjects/genesis01/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 57, in __getattr__
self._setup(name)
  File "/home/nadeem/PycharmProjects/genesis01/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
  File "/home/nadeem/PycharmProjects/genesis01/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 107, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/nadeem/PycharmProjects/genesis01/genesis01/genesis01/settings.py", line 88, in <module>
'NAME': os.environ['babies'],
  File "/usr/lib/python3.6/os.py", line 669, in __getitem__
    raise KeyError(key) from None
KeyError: 'babyies'

我需要能够成功连接到RDS中运行的MySQL实例以进行迁移。

0 个答案:

没有答案