【问题标题】:Difficulty opening port 5432 for PostgreSQL on Ubuntu 12.04在 Ubuntu 12.04 上为 PostgreSQL 打开端口 5432 有困难
【发布时间】:2013-11-10 14:59:21
【问题描述】:

我正在尝试让 postgres 数据库与 django 安装对话。

我已按照此处的步骤详细信息:http://blog.iiilx.com/programming/how-to-install-postgres-on-ubuntu-for-django/

但是,当我使用 syncdb 让 django 更新我的 postgres 数据库时,我收到以下错误:

connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: FATAL:  database "/home/flowcore/django_db" 
does not exist

django_db 是数据库的名称,它确实存在,但在 /home/flowcore/django_db 中当然不存在(这不是 postgres 存储数据的地方!)

settings.py 中的数据库字典如下所示:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.path.join(BASE_DIR, 'django_db'),
        'USER': 'django_login',
        'PASSWORD': 'mypasswordhere',  #obviously i've replaced this with my actual password
        'HOST': 'localhost',
    }
}

我是否必须指定我的 postgres 数据库文件的绝对路径,如果需要,这些文件存储在哪里?

【问题讨论】:

  • 您应该在 settings.py 中显示 DATABASES 字典。
  • 您不需要路径。只是名字。 (“django_db”,我猜)
  • @DanielRoseman 完成,我已将其添加到原始问题中:)
  • @wildplasser 我刚刚在上面添加了我的setting.py - 你可以看到它已经指向了。
  • 不,那行有一个os.path.join()。 (不知道应该怎么做)

标签: python django postgresql ubuntu installation


【解决方案1】:

好吧,由于某种原因,您将完整路径作为 NAME 参数,所以 Django 使用它也就不足为奇了。没有理由这样做,并且您链接到的教程也没有建议这样做。 NAME 是数据库名称本身,正如您所说的只是“django_db”。

【讨论】:

  • 我犯了一个愚蠢的错误。我什至没有想过 os.path.join() 在做什么!谢谢!
猜你喜欢
  • 1970-01-01
  • 2015-05-01
  • 2016-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-12
  • 2015-07-26
  • 2020-06-11
相关资源
最近更新 更多