【问题标题】:Unable to deploy of Heroku because of Python Package with Error由于 Python 包出错,无法部署 Heroku
【发布时间】:2019-07-21 21:26:37
【问题描述】:

我正在尝试将我的 django 应用程序上传到 Heroku。它在本地工作,因为我纠正了错误,但由于某种原因,在我添加白噪声以获取本地文件以便我可以在 Heroku 上部署之后,它不断出现相同的错误。 我正在加载一个本地包 csv-imports,它在第 70 行出现错误。

class ImportModel(models.Model):
    """ Optional one to one mapper of import file to Model """
    #this is the line with the error and I fixed it here with the on_delete
    csvimport = models.ForeignKey(CSVImport, on_delete=models.DO_NOTHING)
    numeric_id = models.PositiveIntegerField()
    natural_key = models.CharField(max_length=100)

但是当我跑步时:

git push heroku master

我在本地解决了以下错误,但似乎不断出现 Heroku。文件已更改。我可能不在 Heroku 给出的正确文件路径上,我的计算机上没有 app/.heroku/。但是,我的电脑上只有一个 csv-imports 安装,并且已经按照上面的方法进行了修复。为什么我不断收到此错误,我该如何解决?

remote:          File "/app/.heroku/python/lib/python3.7/site-packages/csvimport/models.py", line 72, in ImportModel
remote:            csvimport = models.ForeignKey(CSVImport)
remote:        TypeError: __init__() missing 1 required positional argument: 'on_delete'
remote: 
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
emote:        See traceback above for details.
remote: 
remote:        You may need to update application code to resolve this error.
remote:        Or, you can disable collectstatic for this application:
remote: 
remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1
remote: 
remote:        https://devcenter.heroku.com/articles/django-assets
remote:  !     Push rejected, failed to compile Python app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to gentle-lowlands-98196.
remote: 

【问题讨论】:

  • 我认为您遇到了该错误,因为您需要先将更改推送到您的存储库。
  • 您确定在推送之前已将更改提交到 git 吗?
  • 问题是这个 cvs-import 位于不同的文件夹中,它位于 lib/python3.7/site-packages/csv-import 中,而我的项目位于 src/djanopractice/myproject 中。我正在从 myproject 文件夹中推送。我需要从 src 推送吗?
  • @Sam,我很确定我几天前在本地修复了这个错误并今天创建了 git 存储库。

标签: django github heroku csv-import


【解决方案1】:

问题在于您的静态目录,首先您必须运行: “python manage.py collectstatic” 这将为您提供静态目录的路径或异常,例如您使用 STATIC_URL 而没有 STATIC_ROOT 目录。

【讨论】:

    猜你喜欢
    • 2013-10-23
    • 1970-01-01
    • 2020-09-27
    • 2018-01-11
    • 2020-07-20
    • 2021-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多