我終於(想)成功安裝了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