YvesSaintYuran
YvesSaintYuran

Reputation: 41

heroku deployment, relation "django_session" does not exist

I've build a simple browser game on Python+Django, which is using session/cookies to track the score. The game it self doesn't have any database. When I'm deploying to heroku, I got this type of error

ProgrammingError at /
relation "django_session" does not exist
LINE 1: SELECT (1) AS "a" FROM "django_session" WHERE "django_sessio...
                               ^
Request Method: GET
Request URL:    https://lesgogo.herokuapp.com/
Django Version: 3.0.7
Exception Type: ProgrammingError
Exception Value:    
relation "django_session" does not exist
LINE 1: SELECT (1) AS "a" FROM "django_session" WHERE "django_sessio...
                               ^
Exception Location: /app/.heroku/python/lib/python3.8/site-packages/django/db/backends/utils.py in _execute, line 86
Python Executable:  /app/.heroku/python/bin/python
Python Version: 3.8.3
Python Path:    
['/app/.heroku/python/bin',
 '/app',
 '/app/.heroku/python/lib/python38.zip',
 '/app/.heroku/python/lib/python3.8',
 '/app/.heroku/python/lib/python3.8/lib-dynload',
 '/app/.heroku/python/lib/python3.8/site-packages']
Server time:    Sat, 13 Jun 2020 04:00:23 +0000

what I've tried:

python manage.py migrate --fake sessions zero
# then your sessions migrate will be
python manage.py showmigrations
sessions
 [ ] 0001_initial
# then migrate with --fake-initial again
python manage.py migrate --fake-initial

added, and pushed back to heroku, didn't worked.


INSTALLED_APPS = [
    'myapp',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

the versions i'm using

python-3.8.3
asgiref==3.2.7
dj-database-url==0.5.0
Django==3.0.7
django-heroku==0.3.1
gunicorn==20.0.4
psycopg2==2.8.5
pytz==2020.1
sqlparse==0.3.1
whitenoise==5.1.0

PS: it's my first post. Thanks!

Upvotes: 2

Views: 1621

Answers (1)

Ross Symonds
Ross Symonds

Reputation: 710

After following the advice in this link ProgrammingError: relation "django_session" does not exist (it is the link you mention above), I then did

heroku run python manage.py makemigrations sessions
heroku run python manage.py migrate sessions

Upvotes: 5

Related Questions