我试图获得我的第一个django应用程序,但是我遇到这个db错误:
OperationalError:无法连接到服务器:连接拒绝服务器是否在主机localhost上运行,并接受端口5432上的TCP / IP连接?每当我尝试syncdb,迁移或创建uperuser
我正在配置我的DATABASES变量,如:
DATABASES = {'default':dj_database_url.config = os.environ [HEROKU_POSTGRESQL_OLIVE_URL])}还有其他我需要配置或者做错了?
EDIT(SOLVED):
感谢您帮助我缩小问题,找到解决方案。
由于这是我第一次部署到heroku,第一次使用两个勺子django目录格式。我以为做了这样的事情,例如
python manage.py syncdb#将会好起来 / pre>而不是我的设置文件夹看起来像
./settings base.py local.py production.py demo.py #...我需要做
python manage.py syncdb --app.settings.demo解决方案
您的语法似乎在验证您提升的 HEROKU_POSTGRESQL_OLIVE_URL 之后,尝试使用 DATABASE_URL ,尽管即使未被提升也应该可以工作。
$ heroku pg:促销HEROKU_POSTGRESQL_OLIVE_URL然后:
import dj_database_url DATABASES = {'默认':dj_database_url.config(default = os.getenv('DATABASE_URL'))}此设置应该工作。否则,请检查您是否正在使用正确的设置文件。您可以执行以下操作来验证此操作:
$ heroku运行python manage.py shell然后:
>> ;从django.conf导入设置>>>打印设置.DATABASES ['default']并验证结果。
I am trying to get my first django app up, but I'm running into this db error:
OperationalError: could not connect to server: Connection refused Is the server running on host "localhost" and accepting TCP/IP connections on port 5432?This happens whenever I try to syncdb, migrate, or createsuperuser
I am configuring my DATABASES variable like:
DATABASES = {'default' : dj_database_url.config(default=os.environ["HEROKU_POSTGRESQL_OLIVE_URL"]) }Is there something else I need to configure or am doing wrong?
EDIT (SOLVED):
Thanks for helping me narrow down the problem, I've found the solution.
Since this was the first time I deployed to heroku and the first time I used the two scoops django directory format. I thought doing something like
python manage.py syncdb # would be okayinstead beause my settings folder looks like
.../settings base.py local.py production.py demo.py # ...I need to do
python manage.py syncdb --app.settings.demo解决方案
Your syntax seems right, try using DATABASE_URL after verifying you promoted HEROKU_POSTGRESQL_OLIVE_URL, although it should work even when not promoted.
$ heroku pg:promote HEROKU_POSTGRESQL_OLIVE_URLand then:
import dj_database_url DATABASES = { 'default': dj_database_url.config(default=os.getenv('DATABASE_URL')) }This setup should be working. Else, check that you are working on the right settings file. You can verify this by running:
$ heroku run python manage.py shelland then:
>>> from django.conf import settings >>> print settings.DATABASES['default']and verify result.
更多推荐
Heroku Django db postgres错误
发布评论