0

因此,我设法在 heroku 的生产数据库设置之间搞砸了。

在本地运行生产设置我收到错误,

ImproperlyConfigured at /
settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

部署到 Heroku 时出现以下错误:http: //tulsa-staging.herokuapp.com

Exception Value:    

cannot concatenate 'str' and 'NoneType' objects

它似乎与我的数据库设置有关,但我只是不确定如何解决这个问题。

Heroku 的 prod.py 数据库设置

urlparse.uses_netloc.append('postgres')
urlparse.uses_netloc.append('mysql')

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

        DATABASES = {
            'default':{
                'ENGINE':'django.db.backends.postgresql_psycopg2',
                'NAME': url.path[1:],
                'USER': url.username,
                'PASSWORD': url.password,
                'HOST': url.hostname,
                'PORT': url.port
            }
        }

except Exception:
    print 'Unexpected error:', sys.exc_info()

关于如何解决这个问题的任何想法?

4

1 回答 1

1

Why aren't you using dj-database-url?

It makes this so much easier:

import dj_database_url

DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}

It automatically looks for and parses the value in env['DATABASE_URL'], falling back to what you pass into default.

It's what Heroku actually recommends you use.

于 2013-02-27T07:20:05.200 回答