我是Heroku和Django/Python的新手。我希望能为我遇到的一个问题找到答案。我一直在Heroku的开发中心学习入门教程:https://devcenter.heroku.com/articles/django
当运行命令并将应用程序代码推送到Heroku时,一切都正常工作。例如,当我运行CLI命令"heroku run python manage.py syncdb"时,一切都按预期工作,没有任何错误。然而,当我尝试在本地运行相同的命令"python manage.py syncdb"时,我会得到以下输出和错误:
Scotts-MacBook-Pro:bonavina scottklieberman$ python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
...
File "/Library/Python/2.7/site- packages/django/db/backends/postgresql_psycopg2/base.py", line 162, in _cursor
raise ImproperlyConfigured("You need to specify NAME in your Django settings file.")
django.core.exceptions.ImproperlyConfigured: You need to specify NAME in your Django settings file.
然后我回去查看了我的settings.py文件。根据Heroku教程,我没有在设置文件中指定NAME,因为我使用的是dj_database_url。我很好奇为什么它在本地失败(为什么它需要NAME),而它在Heroku上编译成功。如有任何帮助,我们将不胜感激。如果您需要任何其他信息来诊断该问题,请告诉我。
最佳,Scott
dj_database_url
使用环境变量DATABASE_URL
的值,该值在Heroku上设置,但可能不会在本地环境中设置(除非您自己设置)。