【发布时间】:2015-02-28 18:54:49
【问题描述】:
我在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。
-
我遇到了类似的问题,但我的问题是我会在本地机器上的 pgAdmin 中创建数据库,但在服务器的命令行中它会自动将所有内容都小写。在我的设置文件中,它是大写的,所以 Django 无法识别数据库。这里似乎不是问题,但其他人可能会遇到它。
标签: python django database postgresql ubuntu-12.04