已解决:我使用的是USERNAME,而不是以前尝试使用Postgres驱动程序的用户。
我试图将我的django项目连接到RDS MySQL数据库。我可以使用MySQL Workbench和mysql命令行中的凭据进行正常连接。
我已将AWS安全组和VPC安全组设置为 所有交通|全部|全部| 0.0.0.0/0
我们说我的凭据是 用户:abc 密码:密码
当我运行python manage.py migrate
时,它尝试使用Mike登录,而不是因为某种未知原因而登录abc(Mike是Windows用户)。我该如何防止这种情况?附件是我的settings.py:
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'playercomp',
'USERNAME': 'abc',
'PASSWORD': 'password',
'HOST': 'xxx.xxx.us-west-2.rds.amazonaws.com',
'PORT': '3306',
}
}
manage.py
#!/usr/bin/env python
try:
import pymysql
pymysql.install_as_MySQLdb()
except ImportError:
print "Failed to import pymysql"
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "playercomp.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv)
错误追踪:
Traceback (most recent call last):
File "manage.py", line 27, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
utility.execute()
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\core\management\__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\core\management\base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\core\management\base.py", line 342, in execute
self.check()
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\core\management\base.py", line 374, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\core\management\commands\migrate.py", line 61, in _run_checks
issues = run_checks(tags=[Tags.database])
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\core\checks\database.py", line 10, in check_database_backends
issues.extend(conn.validation.check(**kwargs))
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\db\backends\mysql\validation.py", line 9, in check
issues.extend(self._check_sql_mode(**kwargs))
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\db\backends\mysql\validation.py", line 13, in _check_sql_mode
with self.connection.cursor() as cursor:
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\db\backends\base\base.py", line 231, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\db\backends\base\base.py", line 204, in _cursor
self.ensure_connection()
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\db\backends\base\base.py", line 199, in ensure_connection
self.connect()
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\db\utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\db\backends\base\base.py", line 199, in ensure_connection
self.connect()
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\db\backends\base\base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\django\db\backends\mysql\base.py", line 263, in get_new_connection
conn = Database.connect(**conn_params)
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\pymysql\__init__.py", line 90, in Connect
return Connection(*args, **kwargs)
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\pymysql\connections.py", line 688, in __init__
self.connect()
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\pymysql\connections.py", line 906, in connect
self._request_authentication()
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\pymysql\connections.py", line 1114, in _request_authentication
auth_packet = self._read_packet()
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\pymysql\connections.py", line 981, in _read_packet
packet.check_error()
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\pymysql\connections.py", line 393, in check_error
err.raise_mysql_exception(self._data)
File "C:\Users\Mike\Envs\playercomp\lib\site-packages\pymysql\err.py", line 107, in raise_mysql_exception
raise errorclass(errno, errval)
django.db.utils.OperationalError: (1045, u"Access denied for user 'Mike'@'host-yy-yy.zzz.zz.com' (using password: YES)")
答案 0 :(得分:0)
我在DATABASES默认值中添加了一个字段'USER':'abc',并且有效。