Postgres settings for Django on Google App Engine Flexi

喜欢而已 提交于 2019-12-23 21:23:34

问题


I am trying to setup django with postgres on app engine flexible environment.

I followed the instructions from here: https://cloud.google.com/appengine/docs/flexible/python/using-cloud-sql-postgres

My django settings:

DATABASES = {
    'default': {
            'ENGINE': 'django.db.backends.postgresql',
            'NAME': '<db-name>',
            'USER': '<user-name>',
            'PASSWORD': '<password>',
            'HOST': '/cloudsql/<instance-connection-name>,
            'PORT': '5432'
        },
}

app.yaml:

beta_settings:
    cloud_sql_instances: <instance-connection-name>

Error I am getting is:

could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/cloudsql/<instance-connection-name>/.s.PGSQL.5432"?

Please help with the correct settings.


回答1:


The problem resolved itself. I didn't change anything in my code. Here are the steps to use postgresql with django in app engine flexible environment:

https://github.com/GoogleCloudPlatform/python-docs-samples/issues/870

EDIT:

You have to enable the cloud sql api to get it running properly.

checkout this comment: https://github.com/GoogleCloudPlatform/python-docs-samples/issues/870#issuecomment-298152847




回答2:


I had a similar problem, it ends up that I had skipped enabling the sqladmin API.

To see if this is the problem you can check the logs for the instance. Near the top (before gunicorn starts) there will be an error along the lines of:

googleapi: Error 403: Access Not Configured. Cloud SQL Administration API has not been used in project ######## before or it is disabled.

That check is made only when the instance first starts, so once you've enabled the API, you need to re-deploy or otherwise restart your instances. Many of the people reporting this issue elsewhere talk about it magically fixing itself, and I'm guessing the instances got restarted.




回答3:


If you turn on api and it does not help try to change database engine in Django

'ENGINE': 'django.db.backends.postgresql'

to

 'ENGINE': 'django.db.backends.postgresql_psycopg2'


来源:https://stackoverflow.com/questions/42950418/postgres-settings-for-django-on-google-app-engine-flexi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!