gpt4 book ai didi

python - Django Postgres 导入错误 : is the server running locally and accepting connections on Unix domain socket?

转载 作者:行者123 更新时间:2023-11-28 18:34:29 24 4
gpt4 key购买 nike

我在一个共享的 bluehost 机器上运行。奇怪的是我的网站在线运行良好。我可以很好地打开 django/admin/站点。但是,我无法运行 manage.py migrate 或通过 manage.py shell 对数据库进行任何查询。这是我收到的错误:

File "/home2/univetg1/python3/lib/python3.5/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 172, in get_new_connection
connection = Database.connect(**conn_params)
File "/home2/univetg1/python3/lib/python3.5/site-packages/psycopg2/__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.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"?

这是我在 settings.py 中的数据库设置:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'univetg1_lunchbox',
'USER': 'username',
'PASSWORD': 'password',
'HOST': '',
'PORT': '',
}
}

这很奇怪,因为我没有玩过我的 settings.py 文件或任何东西,直到刚才一切都运行良好。

最佳答案

如果您遇到如下错误:

ERROR: 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"?

那么服务器是:

  • 没有运行;
  • 在 5432 以外的端口上运行;或
  • 配置了不同的 unix_socket_directories 路径,因此它不会监听 /tmp 中的套接字

我们知道服务器正在运行,因为您的 Django 站点正在运行。所以这大概是连接信息的问题。假设 Django 实际上正在使用 settings.py 中的数据,它也必须在端口 5432 上。

所以我的猜测是它使用了不同的 unix_socket_directories。也许您在运行时在交互式控制台上链接到的 libpq 与运行服务时链接到的不同。

您可以通过将主机指定为 localhost 来尝试通过 TCP/IP 进行连接。否则,请检查 postgresql.confunix_socket_directories 的设置,并将其设置为您的 HOST

关于python - Django Postgres 导入错误 : is the server running locally and accepting connections on Unix domain socket?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33769258/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com