I'm trying to upload my django application on Heroku. It works on local because I corrected the error, but for some reason after I added whitenoise to get local files so that I can deploy on Heroku, it keeps bringing up the same error.
I am loading a local package csv-imports and it has an error on line 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)
However when I run:
git push heroku master
I get the following error which I have fixed on my local, but seems to keep coming up with Heroku. The file has been changed. I might not be on the right file path given by Heroku there is no app/.heroku/ on my computer. But, there is only one installation of csv-imports on my computer and that one has been fixed as above. Why do I keep getting this error and how do I fix it?
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:
Problem is with your static directory, first you have to run:
"python manage.py collectstatic"
This will give you the path of your static directory or an exception like you are using STATIC_URL without STATIC_ROOT Directory.
Related
I am trying to deploy a Django app via Heroku for the first time.
When I run git push heroku master it returns this error:
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: ! No default language could be detected for this app.
remote: HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically.
remote: See https://devcenter.heroku.com/articles/buildpacks
remote:
remote: ! Push failed
remote: !
remote: ! ## Warning - The same version of this code has already been built: e6acd22b123b939729546f4f06f368a8855a4744
remote: !
remote: ! We have detected that you have triggered a build from source code with version e6acd22b123b939729546f4f06f368a8855a4744
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 vygrapp.
remote:
To https://git.heroku.com/vygrapp.git
! [remote rejected] master -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/vygrapp.git'
Following similar problems on SO I believe I have my file structure correctly configured - with git deployed from same place as my Procfile etc. I also have a requirements.txt file which I believe tells Heroku it's a python app - so I can't figure out why the buildpack isn't working.
Based on comments and feedback I moved all folders into root directory but receive the same error.
Heroku only looks for your Procfile, requirements.txt, and runtime.txt in the root directory of your project. Move them up a level so they're beside your .gitattributes.
That should let Heroku detect that this is a Python project and get past the current error.
But your project still won't run. Out of the box, Heroku will expect your Django project to also be in the root directory of your repository. You can probably get it to work from a subdirectory by playing around with the DJANGO_SETTINGS_MODULE environment variable and / or PYTHONPATH, but the easiest solution is to move your entire project up a directory.
I suggest you move everything from anybody/anybody1/ to anybody/, then delete the now empty anybody/anybody1/ directory.
Then commit, and redeploy.
I am trying to deploy a django app to heroku, and it is causing me errors. In the process of debugging when I run the command
heroku local web -f Procfile.windows
it shows me the following error:
[FAIL] No Procfile and no package.json file found in Current Directory - See run-foreman.js --help
From the application structure that is attached you can see that there is the Proc file and the content of the Procfile is as following:
web: gunicorn klaviyo_integration.wsgi --log-file -
Any guesses what might be wrong?
And I am using Windows as OS, in case there is a problem with gunicorn on that sense.
It might caused by wrong Procfile syntax.
Try to remove any comment from your Procfile. It works in my case.
My original Procfile:
# Some comment here
web: python start.py --port %PORT%
After removing the comment, no more errors occur.
web: python start.py --port %PORT%
I had same problem with tmp directory.
I could solve it by removing from .gitignore. check Procfile in .gitignore
BLUF: Try verifying your Procfile is actually saved as a UTF-8 file
How to debug your issue better:
This is a generic error heroku-cli returns whenever it can't parse your Procfile, and unfortunately it's logging does a poor job of telling you what the problem is.
For me, I ran into this error when I tried creating the Procfile in Pycharm on Windows
$ heroku local
[WARN] Cannot read property '1' of null
[FAIL] No Procfile and no package.json file found in Current Directory - See run --help
TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at Index.run (/usr/local/lib/heroku/node_modules/#heroku-cli/plugin-local/lib/commands/local/index.js:30:38)
at Index._run (/usr/local/lib/heroku/node_modules/#oclif/command/lib/command.js:44:31)
Turns out, the heroku server is gives much better error messages!
When I tried pushing the changes directly to heroku that I got a real lead towards the true root cause:
$ git push heroku main
Counting objects: 102, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (96/96), done.
Writing objects: 100% (102/102), 33.93 KiB | 808.00 KiB/s, done.
Total 102 (delta 31), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
git bremote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Python app detected
remote: -----> Using Python version specified in runtime.txt
remote: Traceback (most recent call last):
remote: File "/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136/vendor/runtime-fixer", line 8, in <module>
remote: r = f.read().strip()
remote: File "/usr/lib/python3.8/codecs.py", line 322, in decode
remote: (result, consumed) = self._buffer_decode(data, self.errors, final)
remote: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
remote: /tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136/bin/steps/python: line 5: warning: command substitution: ignored null byte in input
remote: ) is not available for this stack (heroku-20).
remote: ! Aborting. More info: https://devcenter.heroku.com/articles/python-support
remote: ! Push rejected, failed to compile Python app.
remote:
rremote: ! Push failed
anremote: Verifying deploy...
remote:
remote: ! Push rejected to salty-ocean-58897.
remote:
To https://git.heroku.com/salty-ocean-58897.git
! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/salty-ocean-58897.git'
Specifically, note the line:
remote: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
That's what pointed me in the right direction and led me to realizing Pycharm had created my Procfile, runtime.txt, and requirements.txt files as utf-16 files. Converting them to utf-8 fixed the error.
So I try to make a very simple test app to run with Heroku. Its my 3rd attempt from complete scratch. I have a single python file with very minimal content
from flask import Flask
app = Flask(__name__)
#app.route("/")
def test():
return "test"
if __name__ == '__main__':
app.run()
the file is named test.py, my directory also includes Procfile
web: gunicorn app:test
and requirments.txt
click==7.1.2
Flask==1.1.2
gunicorn==20.1.0
itsdangerous==1.1.0
Jinja2==2.11.3
MarkupSafe==1.1.1
Werkzeug==1.0.1
to top it off I have gitignore to ensure IDE files do not interfere,
.idea
.Heroku.iml
and runtime.txt
python-3.6.0
I then try to create an app using
heroku create <appname>
I then use second URL it returns in the command
git remote add heroku <url>
. Afterwards I do
git add .
git commit -m "some message"
git push heroku main
and get the following error.
To https://git.heroku.com/forgotten-fox.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/forgotten-fox.git'
I then try to do it using
git push heroku master
instead but no changes occur.
I also try to force it to use python build pack with
heroku buildpack:set heroku/python --app <appname>
as above the error it states that
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
I don't know how to use git mostly, but my friend advised me to create remote repository and attach it to Heroku but I was not able to find how to do the attachment.
If anyone knows what causes that and / or how to solve it i would really appreciate if you share the knowledge.
Update:
Thanks for pointing out wrong name for requirements file, I've renamed it. I`ve also changed my Procfile to
web: gunicorn test:app
.
Sadly it doesn't resolve the issue (yes I did commit and push the changes made).
Here is the error messages:
for git push heroku master :
Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 6 threads
Compressing objects: 100% (9/9), done.
Writing objects: 100% (11/11), 1.66 KiB | 1.66 MiB/s, done.
Total 11 (delta 0), 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: 36fb38193ecf8aa8d27f79682de049be81cb8807
remote: !
remote: ! We have detected that you have triggered a build from source code with version 36fb38193ecf8aa8d27f79682de049be81cb8807
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 forgotten-fox.
remote:
To https://git.heroku.com/forgotten-fox.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/forgotten-fox.git'
and here for git heroku push main:
error: src refspec main does not match any
error: failed to push some refs to 'https://git.heroku.com/forgotten-fox.git'
.
Update
Ok, sorry everyone, I'm generally retarded. I missed the obvious part of error about build back, here it states the final fix I needed for my app to work.
the issue is that you have to use
web: gunicorn test:app
instead of
web: gunicorn app:test
the correct format is
gunicorn <filename>:<app object>
I'm trying to install a django app to Heroku for the first time. I've been following tutorials and things were going fine until git push heroku master. I get an error with postgrequl/psycopg2:
Collecting psycopg2==2.6.2 (from -r /tmp/build_9a1b9401a05f6186e32ef1f993bdd183/requirements.txt (line 10))
remote: Downloading blah...blah../bc/psycopg2-2.6.2.tar.gz (376kB)
remote: Complete output from command python setup.py egg_info:
remote: running egg_info
remote: creating pip-egg-info/psycopg2.egg-info
remote: writing pip-egg-info/psycopg2.egg-info/PKG-INFO
remote: writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
remote: writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
remote: writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'
remote: Error: could not determine PostgreSQL version from '10.5'
remote:
remote: ----------------------------------------
remote: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-mu5yzi1s/psycopg2/
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to django-randomizer.
I did some searches and I read where other people had problems because they had an older version of psycopg2. So I edited my requirements.txt file to include psycopg2-2.7.5, which is the latest. I think try `git push heroku master' again and I get the same error. The error references psycopg2-2.6.2.
I even deleted my app and started again, but when it came to the git push, I get the same error. At this time I think that git is in some state where it keeps trying to do the push that already failed. I'm not sure though. Any ideas?
git reflog:
5fd142e (HEAD -> deployheroku, origin/deployheroku) HEAD#{0}: pull origin deployheroku: Fast-forward
df048a9 (origin/master, origin/HEAD, master) HEAD#{1}: reset: moving to HEAD^
5fd142e (HEAD -> deployheroku, origin/deployheroku) HEAD#{2}: commit: change settings and wsgi for heroku
df048a9 (origin/master, origin/HEAD, master) HEAD#{3}: checkout: moving from master to deployheroku
df048a9 (origin/master, origin/HEAD, master) HEAD#{4}: commit: restore local version
873d636 HEAD#{5}: commit: updated psycopg2 in requirements.txt
aebfe43 HEAD#{6}: commit: get files ready for heroku
6273553 HEAD#{7}: commit: removed old files
9b2c347 HEAD#{8}: commit: update with new app name
6b4103d HEAD#{9}: clone: from https://github.com/shmish/django-randomizer.git
My requirements.txt is:
certifi==2018.8.13
chardet==3.0.4
defusedxml==0.5.0
Django==2.0.8
django-allauth==0.36.0
django-filter==2.0.0
docopt==0.6.2
idna==2.7
oauthlib==2.1.0
psycopg2==2.7.5
python-decouple==3.1
python3-openid==3.1.0
pytz==2018.5
requests==2.19.1
requests-oauthlib==1.0.0
urllib3==1.23
whitenoise==4.0
yarg==0.1.9
$ git show master:requirements.txt | grep psycopg2
psycopg2==2.6.2
So you've deployed a wrong branch. Either deploy deployheroku or update requirements.txt in master.
When I'm trying to deploy a Django app to Heroku, encounter the identical problem as python - Collectstatic error while deploying Django app to Heroku - Stack Overflow
it starts to build, download and installs everything, but that's what I get when it comes to collecting static files:
$ git push heroku master
Counting objects: 5375, done.
Total 5375 (delta 1092), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing requirements with pip
remote:
...
remote:
remote: ! Error while running '$ python manage.py collectstatic --noinput'.
remote: 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 fierce-cove-94300.
remote:
To https://git.heroku.com/fierce-cove-94300.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/fierce-cove-94300.git'
I tried all its answers, but not helps.
Additional I tried Django and Static Assets | Heroku Dev Center to configure the setting and install whitenoise and commit changes.
The problem is not solved.
Disable auto collectstatic:
heroku config:set DISABLE_COLLECTSTATIC=1
Then push your project to heroku. After the deploy is done, manually collectstatic as below:
heroku run python manage.py collectstatic
If you still get errors, your static files config is probably the reason. Try making it simple, remove whitenoise and use a s3 bucket for example.