English 中文(简体)
Deploing Django to Heroku (Psycopg2 Error)
原标题:Deploying Django to Heroku (Psycopg2 Error)

在从她的oku和django开始获得指南之后,我就这样说了。 然而,在我指挥下:

heroku run python manage.py syncdb

我发现这一错误。

psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" and accepting
TCP/IP connections on port 5432?

我假定,这意味着 d草已经设立,但......因此,我人工添加了共有的_子选择:

heroku addons:add shared-database:5mb

但是,我仍然有同样的错误。 什么?

最佳回答

我的表象结构是......oku 。

toplevel
  requirements.txt
  myapp
    manage.py
    all other django stuff
问题回答

http://www.hchr.org。

正如@mipadi在此指出的(http://stackoverflow.com/questions/13001031/django-heroku-makings-injection/13092534),它实际上可以简单明了:

import dj_database_url

DATABASES = { default  : dj_database_url.config() }

如果你有一张DATABASE,就可以做到这一点。 URL enverra set. 她:pg_promote到那里去。 详情如下:


• 确保你在你本人的oku中担任职务

heroku addons:add heroku-postgresql:dev

步骤1:在贵国数据库中标出

heroku config | grep POSTGRESQL

产出将看上去:

HEROKU_POSTGRESQL__URL: postgres://user:password@host:5432/blabla

第2步:从前一个步骤(例如欧洲航空研究公司-POSTGRESQL_ROSE_URL)中删除名字,并将其放在你的环境档案中。

DATABASES = { default : dj_database_url.config(default=os.environ["HEROKU_POSTGRESQL_ROSE_URL"])}

正如Ted所指出的,有办法向DATABASE推广彩色URL。 URL变量:

heroku pg:promote HEROKU_POSTGRESQL_ROSE_URL

之后,你的数据库环境可使用DATABASE。 URL, 而不是更外观的彩色

DATABASES = { default : dj_database_url.config(default=os.environ["DATABASE_URL"])}

Bob is your uncle

我通过在环境中增加以下法典来开展工作。 我本人似乎出于某种原因,Heroku的确没有给我增加。

Normally it always added the code on Heroku dynamically but I guess after django 1.4 it didnt do it anymore for some reason. Or I was just doing something wrong.

不管怎么说,这部法律只是对你们的环境适用。 它应当像以前那样工作。

import sys
import urlparse
import os


# Register database schemes in URLs.
urlparse.uses_netloc.append( postgres )
urlparse.uses_netloc.append( mysql )

try:

    # Check to make sure DATABASES is set in settings.py file.
    # If not default to {}

    if  DATABASES  not in locals():
        DATABASES = {}

    if  DATABASE_URL  in os.environ:
        url = urlparse.urlparse(os.environ[ DATABASE_URL ])

        # Ensure default database exists.
        DATABASES[ default ] = DATABASES.get( default , {})

        # Update with environment configuration.
        DATABASES[ default ].update({
             NAME : url.path[1:],
             USER : url.username,
             PASSWORD : url.password,
             HOST : url.hostname,
             PORT : url.port,
        })
        if url.scheme ==  postgres :
            DATABASES[ default ][ ENGINE ] =  django.db.backends.postgresql_psycopg2 

        if url.scheme ==  mysql :
            DATABASES[ default ][ ENGINE ] =  django.db.backends.mysql 
except Exception:
    print  Unexpected error: , sys.exc_info()

我有同样的问题,这就是我如何解决这一问题。

步骤1: 菲利普第1号步骤是获取数据库名称(栏目)

步骤2:

$ heroku pg:promote HEROKU_POSTGRESQL_<COLOR> 

导致产出

Promoting HEROKU_POSTGRESQL_<COLOR> to DATABASE_URL... done

你们需要这样做。 txt:

psycopg2

缺席,Heroku configures 邮政数据库,并向您的环境注入代码(https://devcenter.heroku.com/articles/django#postgres_database_config)。 从环境变量DATABASE_URL来看,这确实需要安装心理镜头。





相关问题
摘录数据

我如何将Excel板的数据输入我的Django应用? I m将PosgreSQL数据库作为数据库。

Postgres dump of only parts of tables for a dev snapshot

On production our database is a few hundred gigabytes in size. For development and testing, we need to create snapshots of this database that are functionally equivalent, but which are only 10 or 20 ...

How to join attributes in sql select statement?

I want to join few attributes in select statement as one for example select id, (name + + surname + + age) as info from users this doesn t work, how to do it? I m using postgreSQL.

What text encoding to use?

I need to setup my PostgreSQL DB s text encoding to handle non-American English characters that you d find showing up in languages such as German, Spanish, and French. What character encoding should ...

SQL LIKE condition to check for integer?

I am using a set of SQL LIKE conditions to go through the alphabet and list all items beginning with the appropriate letter, e.g. to get all books where the title starts with the letter "A": SELECT * ...

热门标签