我一直遇到无法连接到数据库的问题:
psycopg2.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket “/tmp/.s.PGSQL.5432”?
我做了一些阅读,似乎这是一个很常见的问题,大多数人通过检查端口是否正确来解决,即在他们的 setup.py 中将 5432 更改为 5433。但这似乎不是我的问题——在 /opt/bitnami/postgresql 目录中,我看到了 .s.PGSQL.5432。我可以登录 psql,它似乎工作正常。我认为默认数据库名称是 postgresql,但我也尝试使用名为 djangostack 的数据库名称,但它也不起作用。我在 Django 的 setting.py 中的数据库信息如下所示:
DATABASES = {
'default': {
'ENGINE': 'postgresql_psycopg2', #'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'postgres', # Or path to database file if using sqlite3.
'USER': 'postgres', # Not used with sqlite3.
'PASSWORD': 'bitnami', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '5432', # Set to empty string for default. Not used with sqlite3.
}
我查看 /tmp/ 目录,那里没有任何东西,无论是隐藏的还是其他的。应该有吗?有谁知道我做错了什么?我愚蠢地覆盖了原始示例项目,所以我看不到那里的设置。
非常感谢,亚历克斯