![](/img/trans.png)
[英]PostgreSQL with OSX Mavericks and Psycopg2 not able to connect with Django Localhost on Mac
[英]Not able to connect postgresql with django
我已經在postgresql
創建了一個名為testdb1
的數據庫,並嘗試將其與django
應用程序連接。 但是,當我運行python manage.py syncdb
,出現錯誤django.db.utils.OperationalError: FATAL: database "testdb1" does not exist
。 數據庫確實存在,因為已通過以下確認:
archit@archit-Inspiron-5520:~/Documents/DjangoLabs/gswd$ psql -U postgres
Password for user postgres:
psql (9.1.14)
Type "help" for help.
postgres=# \connect testdb1
You are now connected to database "testdb1" as user "postgres".
testdb1=# \d
List of relations
Schema | Name | Type | Owner
--------+---------+-------+----------
public | company | table | postgres
(1 row)
在settings.py
我有:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'testdb1',
'USER': 'postgres',
'PASSWORD': 'admin',
'HOST': 'localhost',
'PORT': '',
}
}
在/etc/postgresql/9.1/main/pg_hba.conf
:
# Database administrative login by Unix domain socket
local all postgres md5
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
local all postgres md5
編輯:
\\du
命令給出:
testdb1=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
archit | Superuser, Create role, Create DB, Replication | {}
postgres | Superuser, Create role, Create DB, Replication | {}
任何幫助,將不勝感激。
刪除數據庫並重新創建數據庫。
在settings.py中寫'PORT'='5432'或'5433',因為這是所有postgresql中的通用端口。
然后執行syncdb或遷移。
由於您的表格是在沒有Django工具的情況下創建的。 您將需要寫下一個Model類,並設置一些有關表的“自定義”名稱格式的Metal信息: https : //docs.djangoproject.com/en/1.7/ref/models/options/#table-names
如果可以,我建議您刪除該表並使用Django ORM建立數據庫。 它比用SQL編寫所有內容更快,更簡單: https : //docs.djangoproject.com/en/1.7/intro/tutorial01/#creating-models
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.