【问题标题】:PostgreSQL & Heroku - cannot connect to the databasePostgreSQL & Heroku - 无法连接到数据库
【发布时间】:2013-04-19 14:57:04
【问题描述】:

我正在尝试通过我的 Django 应用使用 South 向表中添加一列,但在运行 python manage.py migrate <app name> 命令时不断收到以下错误:

conn = _connect(dsn, connection_factory=connection_factory, async=async)
psycopg2.OperationalError: could not translate host name "ec2-107-21-99-105.comp
ute-1.amazonaws.com" to address: Temporary failure in name resolution

有人知道为什么会这样吗?我是 South 和 PostgreSQL 数据库管理系统(Heroku 使用)的新手,所以我有点困惑。

【问题讨论】:

  • 似乎是 DNS 问题,无法翻译 ec2-107-21-99-105.compute-1.amazonaws.com 地址。
  • 地址是什么?数据库位于何处?这是我的问题还是 Heroku 的问题?
  • 您是否在任何地方定义了此地址? ec2-107-21-99-105.compute-1.amazonaws.com,也许在你的 settings.py 中?
  • 这是我定义的...DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
  • 试试这一行:'default': dj_database_url.config(default=os.environ.get('DATABASE_URL'))

标签: django postgresql django-south


【解决方案1】:

确保您在settings.py 中定义了默认数据库,如下所示:

DATABASES = {
    'default': dj_database_url.config(default=os.environ.get('DATABASE_URL'))
}

【讨论】:

    猜你喜欢
    • 2014-03-30
    • 2013-04-05
    • 1970-01-01
    • 2014-03-04
    • 1970-01-01
    • 2017-11-27
    • 2013-10-07
    • 1970-01-01
    • 2022-12-03
    相关资源
    最近更新 更多