【发布时间】:2018-02-26 15:04:38
【问题描述】:
我正在努力在 heroku 上部署我的应用程序。主要是数据库配置问题。
这是settings.py文件的底部,
import dj_database_url
DATABASES = { 'default': dj_database_url.config() }
try:
from .local_settings import *
except ImportError:
pass
这是我的 local_settings.py 文件,
导入操作系统 BASE_DIR = os.path.dirname(os.path.dirname(文件))
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'test',
'USER': 'test',
'PASSWORD': 'postgres',
'HOST': 'localhost',
'PORT': 5432,
}
}
我可以成功运行heroku local web。
但是当我运行时,heroku run python manage.py migrate,它给了我错误,
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
当我跑步时,heroku run python manage.py shell,
然后运行
>>> import dj_database_url
>>> dj_database_url.config()
我得到了字典,提供了有关数据库的完整信息。
问题出在哪里?
【问题讨论】: