Djangoでcloud sqlに接続出来ない。
https://github.com/priyankavergadia/Django-Dialogflow-GoogleVisionAPI
↑のDjangoのチャットボットをリンク先のページのドキュメントを元に、動かそうとしているのですが、「Build and run the app locally」のところの、
python manage.py makemigrations
を実行したところ下記エラーが出てきてしまいます。
C:\Users\ellay\Django-Dialogflow-GoogleVisionAPI>python manage.py makemigrations
Traceback (most recent call last):
File "C:\Users\ellay\Anaconda3\lib\site-packages\django\db\backends\base\base.py", line 217, in ensure_connection
self.connect()
File "C:\Users\ellay\Anaconda3\lib\site-packages\django\db\backends\base\base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\ellay\Anaconda3\lib\site-packages\django\db\backends\mysql\base.py", line 227, in get_new_connection
return Database.connect(**conn_params)
File "C:\Users\ellay\Anaconda3\lib\site-packages\MySQLdb\__init__.py", line 84, in Connect
return Connection(*args, **kwargs)
File "C:\Users\ellay\Anaconda3\lib\site-packages\MySQLdb\connections.py", line 166, in __init__
super(Connection, self).__init__(*args, **kwargs2)
MySQLdb._exceptions.OperationalError: (1045, "Access denied for user 'test'@'localhost' (using password: NO)")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\ellay\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\ellay\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\ellay\Anaconda3\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\ellay\Anaconda3\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\ellay\Anaconda3\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\ellay\Anaconda3\lib\site-packages\django\core\management\commands\makemigrations.py", line 101, in handle
loader.check_consistent_history(connection)
File "C:\Users\ellay\Anaconda3\lib\site-packages\django\db\migrations\loader.py", line 283, in check_consistent_history
applied = recorder.applied_migrations()
File "C:\Users\ellay\Anaconda3\lib\site-packages\django\db\migrations\recorder.py", line 73, in applied_migrations
if self.has_table():
File "C:\Users\ellay\Anaconda3\lib\site-packages\django\db\migrations\recorder.py", line 56, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "C:\Users\ellay\Anaconda3\lib\site-packages\django\db\backends\base\base.py", line 256, in cursor
return self._cursor()
File "C:\Users\ellay\Anaconda3\lib\site-packages\django\db\backends\base\base.py", line 233, in _cursor
self.ensure_connection()
File "C:\Users\ellay\Anaconda3\lib\site-packages\django\db\backends\base\base.py", line 217, in ensure_connection
self.connect()
File "C:\Users\ellay\Anaconda3\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\ellay\Anaconda3\lib\site-packages\django\db\backends\base\base.py", line 217, in ensure_connection
self.connect()
File "C:\Users\ellay\Anaconda3\lib\site-packages\django\db\backends\base\base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\ellay\Anaconda3\lib\site-packages\django\db\backends\mysql\base.py", line 227, in get_new_connection
return Database.connect(**conn_params)
File "C:\Users\ellay\Anaconda3\lib\site-packages\MySQLdb\__init__.py", line 84, in Connect
return Connection(*args, **kwargs)
File "C:\Users\ellay\Anaconda3\lib\site-packages\MySQLdb\connections.py", line 166, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (1045, "Access denied for user 'test'@'localhost' (using password: NO)")
インスタンス上のユーザー名・パスワード名が誤ってないかは何度も確認しているので、
問題ないはずなのですが、何度やってもこのエラーが突破できません。
様々検索した中で、
C:\Users\ellay\Django-Dialogflow-GoogleVisionAPI>gcloud sql connect polls-instance2 --user=test
ERROR: (gcloud.sql.connect) HTTPError 400: The incoming request contained invalid data.
上記のsql接続テストでエラーが出ていることが原因なのではとも思っておりますが、
その先の原因特定・解決まで至っておりません。
またDjangoのsetting.py上の記載は下記になっています。
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/michatbot-250809:us-central1:polls-instance2',
'USER': 'test',
'PASSWORD': '',
'NAME': 'polls',
}
}
else:
# Running locally so connect to either a local MySQL instance or connect to
# Cloud SQL via the proxy. To start the proxy via command line:
# $ cloud_sql_proxy -instances=[INSTANCE_CONNECTION_NAME]=tcp:3306
#
# See https://cloud.google.com/sql/docs/mysql-connect-proxy
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '127.0.0.1',
'PORT': '3306',
'NAME': 'polls',
'USER': 'test',
'PASSWORD': '',
}
}
# [END db_setup]
【環境】
■問題の発生した環境
・win10
・Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
・django 2.2.4
・MY SQL 第2世代5.7
調べるべきこと、エラーの可能性などどんな簡単な気付きだけでも結構ですのでアドバイスいただけますと幸いです。