概要
HerokuにDjangoアプリをデプロイ($ git push heroku master
)する際エラーが立て続けに起きたので、その時のエラーと原因・対処法をまとめました。
エラー集
エラー①:App not compatible with buildpack: https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku/python.tgz
実際のエラー文
Enumerating objects: 18, done.
Counting objects: 100% (18/18), done.
Delta compression using up to 12 threads
Compressing objects: 100% (17/17), done.
Writing objects: 100% (18/18), 4.27 KiB | 546.00 KiB/s, done.
Total 18 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/python
remote: -----> App not compatible with buildpack: https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku/python.tgz
remote: More info: https://devcenter.heroku.com/articles/buildpacks#detection-failure
remote:
remote: ! Push failed
remote: !
remote: ! ## Warning - The same version of this code has already been built: e2af378ab78b4f9d724ccfbab21e79cba1bec8d6
remote: !
remote: ! We have detected that you have triggered a build from source code with version e2af378ab78b4f9d724ccfbab21e79cba1bec8d6
remote: ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote: !
remote: ! If you are developing on a branch and deploying via git you must run:
remote: !
remote: ! git push heroku <branchname>:main #これを試してみる
remote: !
remote: ! This article goes into details on the behavior:
remote: ! https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy...
remote:
remote: ! Push rejected to xxxxblog.
remote:
To https://git.heroku.com/xxxxblog.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/xxxxblog.git'
【解決方法】
$ git push heroku <branchname>:main
エラー②: FileNotFoundError: [Errno 2] No such file or directory
実際のエラー文
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/build_15243909/static'
remote:
remote: ! Error while running '$ python manage.py collectstatic --noinput'.
remote: See traceback above for details.
【解決方法】
原因は、.gitignoreファイルに/static
の記述があり、静的ファイルがデプロイ時に見つけられない状態になっていたことでした。この記述を削除し、$ git commit
すると解決されました。
■アプリに静的ファイルが無い場合:$heroku config:set DISABLE_COLLECTSTATIC=1
を実行し、再度$bgit push heroku <branchname>:main
をする。
エラー③:Push failed: cannot parse Procfile.
Push failed: cannot parse Procfile.
remote: ! Please try pushing again.
remote: ! If the problem persists, see https://help.heroku.com/ and provide Request ID 1ec2da4d-fdbf-eae6-0236-721305c905ce.
調べたところ、ProcfileをUTF-8にする必要があることがわかった(参考サイト)ので、UTF-8に変更し再度git push heroku <branchname>:main
をすると、無事にpushできました