难以将现有的django应用程序推送到Heroku。数据库配置不正确

时间:2015-12-23 19:37:17

标签: python django postgresql heroku

所以我有一个完成的Django应用程序,我现在正尝试将它上传到Heroku进行制作,尽管我遇到了一些问题。我一直在关注Heroku网站的教程:

https://devcenter.heroku.com/articles/django-app-configuration#migrating-an-existing-django-project

https://devcenter.heroku.com/articles/getting-started-with-django#declare-process-types-with-procfile

虽然我遇到了这个错误:

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

听起来我需要将我的数据库上传到S3,所以Heroku可以访问它,所以我用这个教程做到了

https://devcenter.heroku.com/articles/heroku-postgres-import-export#import

但我仍然收到错误。以下是我的一些设置。

Settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'texchange',
        'USER': 'joe',
        'PASSWORD': '#######',
        'HOST': 'localhost',
        'PORT': '',
    }
}


STATICFILES_DIRS = (
    ('/static/',
    '/home/joe/Documents/exchange/Texchange/textchange/static/',),
    ('/media/',
    '/home/joe/Documents/exchange/Texchange/textchange/media/'),
)

MEDIA_ROOT = '/home/joe/Documents/exchange/Texchange/textchange/media/'

MEDIA_URL = '/media/'

STATIC_ROOT = '/home/joe/Documents/exchange/Texchange/textchange/static/'

STATIC_URL = '/static/'

# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES['default'] = dj_database_url.config()

# Enable Persistent Connections
DATABASES['default']['CONN_MAX_AGE'] = 500

我究竟不明白什么?任何方向都会受到赞赏,因为这是我第一次使用Heroku和S3上传应用程序。

1 个答案:

答案 0 :(得分:0)

您在评论中提到此问题仅在您运行heroku local时发生,这是完全不同的问题,当然您应该在问题的开头提到一个问题。显然,这并不是关于将你的应用程序上传到Heroku",甚至是关于Heroku没有找到数据库的问题,因为你甚至还没有在Heroku上运行,而是在本地运行。

问题几乎肯定会发生,因为在您的本地环境中,您没有DATABASE_URL,但您可以调用dj_database_url完全覆盖现有的默认数据库配置。

解决这个问题的两种方法是围绕这个电话:

if os.environ['DATABASE_URL']: 
    DATABASES['default'] = dj_database_url.config()

或者更好的是,完全删除DATABASES字典声明并使用该库的默认参数:

DATABASES = {'default': dj_database_url.config(default='postgres://joe:####@localhost/texchange')}