2011-12-22 68 views
5

我沿着this教程來獲取芹菜和django在heroku上運行。Heroku Django芹菜:NameError:name'DATABASES'沒有定義

不過,我得到這個錯誤在我的日誌,當我把在指定代碼爲職工:

2011-12-22T05:31:56+00:00 heroku[web.1]: Starting process with command `python canada/manage.py run_gunicorn -b "0.0.0.0:47336" -w 3` 
2011-12-22T05:31:56+00:00 app[web.1]: Unexpected error: (<type 'exceptions.NameError'>, NameError("name 'DATABASES' is not defined",), <traceback object at 0x11a9560>) 
2011-12-22T05:31:56+00:00 app[web.1]: Traceback (most recent call last): 
2011-12-22T05:31:56+00:00 app[web.1]: File "canada/manage.py", line 11, in <module> 
2011-12-22T05:31:56+00:00 app[web.1]:  import settings 
2011-12-22T05:31:56+00:00 app[web.1]: File "/app/canada/settings.py", line 51, in <module> 
2011-12-22T05:31:56+00:00 app[web.1]:  CELERY_RESULT_DBURI = DATABASES['default'] 
2011-12-22T05:31:56+00:00 app[web.1]: NameError: name 'DATABASES' is not defined 
2011-12-22T05:31:57+00:00 heroku[slugc]: Slug compilation finished 
2011-12-22T05:31:57+00:00 heroku[web.1]: State changed from starting to crashed 
2011-12-22T05:31:58+00:00 heroku[web.1]: Process exited 

我的settings.py看起來像

import djcelery 

djcelery.setup_loader() 

BROKER_BACKEND = "djkombu.transport.DatabaseTransport" 
CELERY_RESULT_DBURI = DATABASES['default'] 
... 

當我加入這個前同步行,CELERY_RESULT_DBURI = DATABASES['default'],它運行良好。據the document

When you deploy a Django application, the compile process appends the following code to your settings.py to use the DATABASE_URL environment variable:

回答

8

的Heroku在settings.py的末尾添加DATABASES配置,因此當您在settings.py中引用DATABASES時,它不存在。

您可以在自己的文件複製的Heroku DATABASES設置(它只是從DATABASE_URL從ENV閱讀,請參閱:django-heroku-template),或使用自己的buildpack

+0

THANKs我讓你知道這是怎麼回事,似乎是正確的 – 2012-01-17 01:02:24

+0

這正是我想要的。謝謝! – 2012-01-22 21:47:42

0

試試這個運行前,你的應用程序:

export DATABASE_URL='postgres://postuser:[email protected]/dbname' 

使用環境變量,以Heroku的最簡單的方法來自動設置數據庫憑據,而無需修改settings.py

+1

你的意思是''heroku運行export DATABASE_URL ='postgres:// postuser:postpassword @ posthost/dbname''然後重新啓動我的應用程序?我將不得不把我所有的數據庫信息?如果Heroku應該附加到我的settings.py,爲什麼它不工作,因爲我沿着教程? – 2011-12-23 01:07:52