I want to add that it is absolutely vital you don’t have any unused imports at the top of your scripts before you deploy your application. Remove all unused imports. Some imports may have been generated automatically and shouldn’t be there at all.
“itpartsecommerce” is in your logs. What is this? Is this a library which is important, or unused?
Clean up imports, delete your requirements.txt file and then generate a new one:
pip freeze >> requirements.txt
If you feel ok about resetting your database, do this:
heroku pg:reset
Then you will have to re-create the superuser and remake migrations:
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
This has resolved all issues for me more than once (I’m on Windows btw).
To get my application deployed without static issues/media issues, I have done this in settings:
# not configuring static files this way
# STATIC_URL = '/static/'
# STATICFILES_DIRS = [
# BASE_DIR / "static",
# ]
import os
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') # the path becomes [project dir]\media\
MEDIA_URL = '/media/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = "/static/"
django_heroku.settings(locals() )
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'whitenoise.runserver_nostatic',
'django_filters',
'django_cleanup.apps.CleanupConfig',
'dashboard.apps.DashboardConfig', # My app
]
Note - I’m using an app called “whitenoise” to serve static files in production, as well as two heroku libraries:
pip install heroku
pip install django_heroku
pip install whitenoise
I have also prevented Heroku from running collectstatic
heroku config:set DISABLE_COLLECTSTATIC=1
More reading here:
This is how I have it changed the database format in settings.py for my Heroku app
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': BASE_DIR / 'db.sqlite3',
# }
# }
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'df32352532kqm1t8',
'USER': 'ykykmwpsnncxna',
'PASSWORD': '1319e9ce252523552235b9c272b3',
'HOST': 'ec2-34-239-241-121.compute-1.amazonaws.com',
'PORT': '5432',
}
}
I changed my credentials for this post with some garbage text as I don’t want people to know my credentials.
https://docs.djangoproject.com/en/4.1/ref/settings/#databases
Figure out what SQL resource you have as default. Is it postgres? Well you might need to click into it, click settings, and view your credentials. If you see a postgres format, you’re probably going to need to change your DB format in settings.py.
Log in to your heroku dashboard here:
https://dashboard.heroku.com/apps
Click resources - open your resource - click settings - view credentials.