运行“python manage.py syncdb”时出错在本地运行相同的命令,但通过Heroku没有错误 [英] Error when running "python manage.py syncdb" locally, but no error when running the same command via Heroku

查看:178
本文介绍了运行“python manage.py syncdb”时出错在本地运行相同的命令,但通过Heroku没有错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是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 
追溯(最近的最后一次调用):
文件manage.py,第10行,< module>
...
文件/Library/Python/2.7/site- packages / django / db / backends / postgresql_psycopg2 / base.py,第162行,_cursor
raise不正确的配置(您需要在Django设置文件中指定NAME。)
django.core.exceptions.ImproperlyConfigured:您需要在Django设置文件中指定NAME。

然后我回去检查了我的settings.py文件。我没有在设置文件中指定NAME,因为我根据Heroku教程使用dj_database_url。我很好奇为什么这在本地失败(为什么要求NAME),而在Heroku上成功编译。任何帮助将不胜感激。如果您有任何其他信息需要诊断问题,请告知我。



Best,
Scott

解决方案

dj_database_url 使用环境变量 DATABASE_URL 的值,在Heroku上设置,但可能不会在您的本地环境中设置(除非您自己设置)。


I am new to Heroku and Django/Python. I was hoping to find an answer for an issue I'm experiencing. I have been following the Getting Started tutorial in Heroku's Dev Center: https://devcenter.heroku.com/articles/django

Everything is working properly when running commands and pushing app code to Heroku. For example, when I run the CLI command "heroku run python manage.py syncdb" everything works as expected with no errors. However, when I try to run the same command locally, "python manage.py syncdb", I am getting the following output and error:

    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.

I then went back and checked my settings.py file. I am not specifying NAME in the settings file because I am using dj_database_url, as per the Heroku tutorial. I am curious as to why this is failing locally (why it is requiring NAME), whereas it is compiling successfully on Heroku. Any help would be greatly appreciated. Let me know if there is any additional information you need to diagnose the issue.

Best, Scott

解决方案

dj_database_url uses the value of the environment variable DATABASE_URL, which is set on Heroku but is probably not set in your local environment (unless you set it yourself).

这篇关于运行“python manage.py syncdb”时出错在本地运行相同的命令,但通过Heroku没有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆