通过Elasticbeanstalk部署到aws时在Django中出现(1049,“未知数据库'face-detection-database'”未知问题)

时间:2019-09-13 23:10:51

标签: django relational-database amazon-elastic-beanstalk

如果我尝试在django中执行任何与数据库相关的任务,即使我有数据库存在,也会显示此错误。 它也打印“人脸检测数据库”行。

if 'RDS_HOSTNAME' in os.environ:
    print("has rds", RDS_DB_NAME)
    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'],
        }
    }

我已经通过Elastic beantalk在AWS上部署了我的应用程序。它显示了以下错误:

InternalError at /registration/process_registration/
(1049, "Unknown database 'face-detection-database'")
Request Method: POST
Request URL:    http://face-detection-env.qdnyceb2ug.us-west-2.elasticbeanstalk.com/registration/process_registration/
Django Version: 2.2.5
Exception Type: InternalError
Exception Value:    
(1049, "Unknown database 'face-detection-database'")
Exception Location: /opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/err.py in raise_mysql_exception, line 109
Python Executable:  /opt/python/run/venv/bin/python3
Python Version: 3.6.8
Python Path:    
['/opt/python/current/app',
 '',
 '/opt/python/run/venv/local/lib64/python3.6/site-packages',
 '/opt/python/run/venv/local/lib/python3.6/site-packages',
 '/opt/python/run/venv/lib64/python3.6',
 '/opt/python/run/venv/lib/python3.6',
 '/opt/python/run/venv/lib64/python3.6/site-packages',
 '/opt/python/run/venv/lib/python3.6/site-packages',
 '/opt/python/run/venv/lib64/python3.6/lib-dynload',
 '/usr/lib64/python3.6',
 '/usr/lib/python3.6']
Server time:    Fri, 13 Sep 2019 14:44:30 -0700

以及当我尝试从注册中检索用户时发生此错误的行。 :

def ValidateData(self, request):
        try:
            username = str(request.POST['enrollment'])
            print(type(username), username)
            user = User.objects.get(username=str(request.POST['enrollment']))        
            print("user exists", user)
            return False
        except User.DoesNotExist:
            print("user not exists")
            return True

我认为我正在收到此错误,因为在部署时我还没有在linux服务器上运行migration命令。因此,我什至按照docs形式aws elastic beantalk告诉在.ebextensions文件夹中创建新的配置文件。如果这样做,然后部署我的应用程序,它将显示另一个错误,如下所示:

/var/log/eb-activity.log
-------------------------------------
[2019-09-13T22:41:36.896Z] INFO  [2184]  - [Application update app-190914_041010@32/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_face_detection_app/Test for Command 01_migrate] : Starting activity...
[2019-09-13T22:41:36.900Z] INFO  [2184]  - [Application update app-190914_041010@32/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_face_detection_app/Test for Command 01_migrate] : Completed activity. Result:

  Completed successfully.
[2019-09-13T22:41:36.900Z] INFO  [2184]  - [Application update app-190914_041010@32/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_face_detection_app/Command 01_migrate] : Starting activity...
[2019-09-13T22:41:37.308Z] INFO  [2184]  - [Application update app-190914_041010@32/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_face_detection_app/Command 01_migrate] : Activity execution failed, because: imported pymysql
  has rds face-detection-database.czfod0wk4014.us-west-2.rds.amazonaws.com
  ##################################################### /opt/python/ondeck/app/static
  Traceback (most recent call last):
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
  self.connect()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 195, in connect
  self.connection = self.get_new_connection(conn_params)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 228, in get_new_connection
  return Database.connect(**conn_params)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/__init__.py", line 94, in Connect
  return Connection(*args, **kwargs)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/connections.py", line 325, in __init__
  self.connect()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/connections.py", line 599, in connect
  self._request_authentication()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/connections.py", line 861, in _request_authentication
  auth_packet = self._read_packet()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/connections.py", line 684, in _read_packet
  packet.check_error()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/protocol.py", line 220, in check_error
  err.raise_mysql_exception(self._data)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
  raise errorclass(errno, errval)
  pymysql.err.InternalError: (1049, "Unknown database 'face-detection-database'")

  The above exception was the direct cause of the following exception:

  Traceback (most recent call last):
  File "/opt/python/run/venv/bin/django-admin.py", line 5, in <module>
  management.execute_from_command_line()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
  utility.execute()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
  self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
  self.execute(*args, **cmd_options)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/base.py", line 361, in execute
  self.check()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/base.py", line 390, in check
  include_deployment_checks=include_deployment_checks,
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 64, in _run_checks
  issues = run_checks(tags=[Tags.database])
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/checks/registry.py", line 72, in run_checks
  new_errors = check(app_configs=app_configs)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/checks/database.py", line 10, in check_database_backends
  issues.extend(conn.validation.check(**kwargs))
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/backends/mysql/validation.py", line 9, in check
  issues.extend(self._check_sql_mode(**kwargs))
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/backends/mysql/validation.py", line 13, in _check_sql_mode
  with self.connection.cursor() as cursor:
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 256, in cursor
  return self._cursor()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 233, in _cursor
  self.ensure_connection()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
  self.connect()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
  raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
  self.connect()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 195, in connect
  self.connection = self.get_new_connection(conn_params)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 228, in get_new_connection
  return Database.connect(**conn_params)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/__init__.py", line 94, in Connect
  return Connection(*args, **kwargs)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/connections.py", line 325, in __init__
  self.connect()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/connections.py", line 599, in connect
  self._request_authentication()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/connections.py", line 861, in _request_authentication
  auth_packet = self._read_packet()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/connections.py", line 684, in _read_packet
  packet.check_error()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/protocol.py", line 220, in check_error
  err.raise_mysql_exception(self._data)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
  raise errorclass(errno, errval)
  django.db.utils.InternalError: (1049, "Unknown database 'face-detection-database'")
   (ElasticBeanstalk::ExternalInvocationError)

,也在此文件中:

/var/log/eb-commandprocessor.log
-------------------------------------
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/connections.py", line 325, in __init__
  self.connect()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/connections.py", line 599, in connect
  self._request_authentication()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/connections.py", line 861, in _request_authentication
  auth_packet = self._read_packet()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/connections.py", line 684, in _read_packet
  packet.check_error()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/protocol.py", line 220, in check_error
  err.raise_mysql_exception(self._data)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
  raise errorclass(errno, errval)
  pymysql.err.InternalError: (1049, "Unknown database 'face-detection-database'")

  The above exception was the direct cause of the following exception:

  Traceback (most recent call last):
  File "/opt/python/run/venv/bin/django-admin.py", line 5, in <module>
  management.execute_from_command_line()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
  utility.execute()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
  self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
  self.execute(*args, **cmd_options)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/base.py", line 361, in execute
  self.check()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/base.py", line 390, in check
  include_deployment_checks=include_deployment_checks,
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 64, in _run_checks
  issues = run_checks(tags=[Tags.database])
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/checks/registry.py", line 72, in run_checks
  new_errors = check(app_configs=app_configs)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/checks/database.py", line 10, in check_database_backends
  issues.extend(conn.validation.check(**kwargs))
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/backends/mysql/validation.py", line 9, in check
  issues.extend(self._check_sql_mode(**kwargs))
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/backends/mysql/validation.py", line 13, in _check_sql_mode
  with self.connection.cursor() as cursor:
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 256, in cursor
  return self._cursor()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 233, in _cursor
  self.ensure_connection()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
  self.connect()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
  raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
  self.connect()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 195, in connect
  self.connection = self.get_new_connection(conn_params)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 228, in get_new_connection
  return Database.connect(**conn_params)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/__init__.py", line 94, in Connect
  return Connection(*args, **kwargs)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/connections.py", line 325, in __init__
  self.connect()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/connections.py", line 599, in connect
  self._request_authentication()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/connections.py", line 861, in _request_authentication
  auth_packet = self._read_packet()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/connections.py", line 684, in _read_packet
  packet.check_error()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/protocol.py", line 220, in check_error
  err.raise_mysql_exception(self._data)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
  raise errorclass(errno, errval)
  django.db.utils.InternalError: (1049, "Unknown database 'face-detection-database'")
   (ElasticBeanstalk::ExternalInvocationError)

0 个答案:

没有答案