我终于(想)成功安装了PostgreSQL并且还安装了psycopg2(我使用的是Windows)。顺便说一句,有一种方法来检查它是否正常工作?无法在Django上运行服务器(连接被拒绝)
好了,想现在是我无法启动服务器,当我键入“蟒蛇manage.py runserver命令”看来这(在命令结束):
conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 8000?
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 8000?
我我搜索了很多关于它的文档,例如in this topic,但我找不到使它正常工作的方法。我已经尝试了pg_hba和postgresql文件中的一些更改,但没有退出。在这一刻,pg_hba样子:
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1 md5
# IPv6 local connections:
host all all 127.0.0.1 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
和PostgreSQL的conf样子:
# - Connection Settings -
listen_addresses = 'localhost' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 8000 # (change requires restart)
max_connections = 100 # (change requires restart)
# Note: Increasing max_connections costs ~400 bytes of shared memory per
# connection slot, plus lock space (see max_locks_per_transaction).
#superuser_reserved_connections = 3 # (change requires restart)
#unix_socket_directories = '' # comma-separated list of directories
# (change requires restart)
#unix_socket_group = '' # (change requires restart)
#unix_socket_permissions = 0777 # begin with 0 to use octal notation
# (change requires restart)
#bonjour = off # advertise server via Bonjour
# (change requires restart)
#bonjour_name = '' # defaults to the computer name
顺便说一句,我的数据库的settings.py这个样子:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'database1',
'USER': 'root',
'PASSWORD': '123456',
'HOST': 'localhost',
'PORT': '8000',
}
}
我的天堂没有创建一个数据库BTW,我该怎么做? PostgreSQL提示符有哪些应用程序?
我会高度赞赏这个问题的帮助我一直在寻找和尝试,但没有退出的日子。非常感谢你。
编辑1:我试图改变settings.py端口5432,但现在的错误信息是一样的,只是改变了口:
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
的配置文件是对这种方式?我应该改变什么吗?我找不到答案。我试着用python manage.py runserver
和两个都指出127.0.0.1:8000
和8001,但没有更改错误消息。出了什么问题?非常感谢你。
Django开发服务器默认运行在8000端口上。为什么你为PostgreSQL服务器选择相同的端口?只需保留默认值(5432),然后重试。连接应该没问题,不要触摸任何配置文件。 – Selcuk
它是否必须位于特定的目录或其他内容?试过但无法弄清楚为什么错误信息仍然存在...非常感谢。 – Jim