Heroku Django db postgres错误

编程入门 行业动态 更新时间:2024-10-27 16:39:04
本文介绍了Heroku Django db postgres错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图获得我的第一个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 okay

instead 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_URL

and 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 shell

and then:

>>> from django.conf import settings >>> print settings.DATABASES['default']

and verify result.

更多推荐

Heroku Django db postgres错误

本文发布于:2023-10-16 05:14:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1496600.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   Django   Heroku   postgres   db

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!