将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?
- 允许远程po stgres访问您的本地数据库。 示例
- 将设置文件更改为这样:
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.