2017-07-31 28 views
0

我正在爲我的後端和數據存儲工作heroku。現在由於一些原因,我想轉移谷歌雲的SQL。我有點困惑,我可以給settings.py中的引擎值來訪問postgre實例。目前我正在這樣做。如何爲dgango應用程序提供引擎值,用於Google雲sql中的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應用程序訪問谷歌雲的SQL實例。 任何幫助將不勝感激。 謝謝。

+0

明顯的問題,但用戶名/密碼是否存在? – Mokadillion

回答

0

錯誤是「主機」。我把我的實例的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', 
    } 
} 
相關問題