2013-05-22 89 views
0

這是我在我的Django項目中的settings.py文件。操作系統:Windows,主機:本地主機使用postgresql-psycopg2運行「python manage.py syncdb」時,Django 1.5中的OperationalError

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.postgresql_psycopg2', 
     'NAME': 'postgres',      
     'USER': 'JESS', 
     'PASSWORD': 'dreamhost', 
     'HOST': 'localhost',      
     'PORT': '5432',      
    } 
} 

我跟着安裝PostgreSQL和psycopg2

http://shivul.wordpress.com/2010/05/07/installing-django-with-postgresql-on-windows-and-ubuntu/

和運行python manage.py syncdb我收到以下錯誤,當從這個博客的說明:

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 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 

我甚至試圖通過PostgreSQL安裝文件中的pgadmin3應用程序編輯設置,它甚至會引發相同的錯誤r

Could not connect to server: Connection refused (0x0000274D/10061) 
Is the server running on host "localhost" (::1) and accepting 
TCP/IP connections on port 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 

我翻翻了類似的問題,在stackoverflow和互聯網,一切都過時或不工作。

+0

在數據庫設置中,爲什麼您的端口設置爲「8000」?更改爲'5432' – karthikr

+0

@karthik:Thankyou ..我仍然面臨另一個問題OperationalError:致命:密碼認證失敗,用戶「JESS」 –

回答

4

您的服務器僅偵聽IPv4,但localhost正在解析主機上的IPv4和IPv6地址。

使用127.0.0.1而不是localhost來強制IPv4連接,或編輯postgresql.conf來告訴您的PostgreSQL也在IPv6上偵聽。在postgresql.conflisten_addresses行上尋求建議,並輸出select version()

+0

謝謝克雷格,我改變了localhost的值,我的listen_address有'*'#所有,但我現在面臨一個新的錯誤:(OperationalError)FATAL:用戶「用戶名」的身份驗證失敗 –

+1

我已經瀏覽了類似問題的其他答案「將pg_hba.conf編輯爲md5 ..」我試過了..and它仍然拋出相同的錯誤 –

+0

@jess。直覺上你編輯了錯誤的'pg_hba.conf'行,或者你忘記了在編輯之後重新啓動PostgreSQL。 –

0

最近我碰到了同樣的消息,但是我的問題的原因/解決方案卻不同。我不完全確定是什麼讓我搞砸了,但我認爲當我看到在manage.py中運行clearsessions函數時會發生什麼。

最後我需要重新啓動postgresql服務。

要做到這一點(Windows 7)中,

  1. 推出你的任務管理器(CTRL + ALT + DEL)
  2. 轉到服務選項卡
  3. 點擊右下角的服務按鈕。

(你也可以搜索在開始菜單的 '查看本地服務')

在服務窗口: 4.查找PostgreSQL的-XXXX。 5.單擊它並在停止時啓動它。

如果它已經在運行,你可能會重新啓動它,因爲你在那裏,看看它是否有幫助。我的問題特別是該服務沒有在啓動時重新啓動。

相關問題