我正在为我的后端和数据存储开发heroku。 现在由于某些原因,我想转向谷歌云SQL。 我有点困惑如何在 settings.py 中给出引擎值以访问 Postgre 实例。 目前我正在这样做。
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'snr',#database name
'USER': 'amad', #database user
'PASSWORD': '1234',#database password
'HOST': '/cloudsql/shopnroar-175407:us-central1:snr-instance1', #connection name
'PORT': '5432', #port
}
}
但它给了我错误" 文件
"/home/amad/python-docs-samples/appengine/flexible/django_cloudsql/env/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/amad/python-docs-samples/appengine/flexible/django_cloudsql/env/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
self.connect()
File "/home/amad/python-docs-samples/appengine/flexible/django_cloudsql/env/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 189, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/amad/python-docs-samples/appengine/flexible/django_cloudsql/env/local/lib/python2.7/site-packages/django/db/backends/postgresql/base.py", line 176, in get_new_connection
connection = Database.connect(**conn_params)
File "/home/amad/python-docs-samples/appengine/flexible/django_cloudsql/env/local/lib/python2.7/site-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: FATAL: password authentication failed for user "admin"
FATAL: password authentication failed for user "admin"
"
有人可以告诉我如何从我的本地 Django 应用程序访问 Google Cloud SQL 上的该实例吗? 任何帮助将不胜感激。 谢谢。
错误出现在"主机"中。 我将实例的 IPv4 地址放在主机中。 之后它现在可以工作了。
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'database_name',
'USER': 'username',
'PASSWORD': 'xxx.xxx.xxx',
'HOST': 'xxx.xxx.xxx.xxx',
'PORT': '5432',
}
}