将Django应用程序的本地postgres数据库部署到heroku? [英] Deploying Django app's local postgres database to heroku?

查看:146
本文介绍了将Django应用程序的本地postgres数据库部署到heroku?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有把我的django应用程序部署在heroku上使用我的本地postgres数据库。

I am unsuccesfully getting my django app deployed on heroku to use my local postgres db.

我的DATABASE设置如下:

My DATABASE settings are as follows:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'mydb',
        'USER': 'foo',
        'PASSWORD': 'bar',
        'HOST': 'localhost',
        'PORT': '',
    }
}

按照 https://devcenter.heroku.com/articles/django 的说明,我添加以下位于我的设置文件底部的代码:

Everything runs fine locally. Following the instructions from https://devcenter.heroku.com/articles/django, I add the following bit a code to the bottom of my settings file:

import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://foo:bar@localhost/mydb')}
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

但是,这会产生以下错误:

However, this produces the following error:

/无法连接到服务器的OperationalError:Connection拒绝服务器在主机localhost(127.0.0.1)上运行服务器并在端口5432上接受TCP / IP连接?

我的django应用运行正常Heroku,除了需要连接到数据库,哪里是这个错误的地方。

My django app runs fine on Heroku, except when it needs to connect to the database, which is where it throws this error.

任何人都知道我在这里做错什么?

Anyone know what I am doing wrong here?

推荐答案


  1. 允许远程po stgres访问您的本地数据库。 示例

  2. 将设置文件更改为这样:

DATABASES = {

DATABASES = {

  'default': {
      'ENGINE': 'django.db.backends.postgresql_psycopg2',
      'NAME': 'your db name',
      'USER': 'your username',
      'PASSWORD': 'password',
      'HOST': 'Your computer's IP',
      'PORT': '6122',
  }

或者您必须将本地数据库克隆到 heroku postgres ,并更改您的设置以使用该数据库。

Or you have to clone your local db to heroku postgres and change your settings to use that db.

这篇关于将Django应用程序的本地postgres数据库部署到heroku?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆