26

Got this error after changing my database from sqlite to postgresql. I've made all my settings changes:

Here's my settings:

DATABASES = {
    'default': {
        'ENGINE': "django.db.backends.postgresql_psycopg2",
        'NAME': "postr1",
        'USER': "zorgan",
        'PASSWORD': config('DB_PASSWORD'),
        'HOST': "localhost",
        'PORT': '',
    }
}

as well as performing makemigrations and migrations which were all successful. So I'm able to succesfully start my local server:

System check identified no issues (0 silenced).
May 15, 2018 - 08:59:39
Django version 1.11.8, using settings 'draft1.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

however when I go to the site it returns this error:

ProgrammingError at /news/
relation "django_session" does not exist
LINE 1: ...ession_data", "django_session"."expire_date" FROM "django_se...

Any idea what the problem is?

10
  • do you have django.contrib.sessions in INSTALLED_APPS? Commented May 15, 2018 at 9:15
  • Yes I do have it Commented May 15, 2018 at 9:15
  • wierd. then please check you have django_session table in your database. in python manage.py dbshell and \dt Commented May 15, 2018 at 9:19
  • 1
    Hmm there is no django_session in my DB. Any idea why? There is django_site though. Commented May 15, 2018 at 9:22
  • 1
    django_site and django_session is totally different. I think sth wrong while you migrate. What happen when migrate again? python manage.py migarte Commented May 15, 2018 at 9:23

4 Answers 4

59

Try fake migrate to zero.

Your migration history shows that sessions table was already made, but you don't have real table.

so following below

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

Then try again.

Sign up to request clarification or add additional context in comments.

Comments

0

I'm using django-v-3

Here is the answer how to solve this issue?

1. python manage.py migrate --fake

2. python manage.py migrate --fake-initial

3. Then write python manage.py runserver

Enjoy

If facing issue use python manage.py help. I hope that you will get the solution.

Comments

0

Since you were using sqlite and changed to Postgres, your user and password no longer work and you got that error. Depending on what is your docker-compose.yml file you can do a migrate command: docker-compose exec web python manage.py migrate and than create a new superuser: docker-compose exec web python manage.py createsuperuser Now your app should work.

Comments

0

Just to add a solution for an additional possible way this failure could occur.

I was struggling with the session tables not being created.

I tried the fake migration reset strategy suggested by @seuling and still was not getting the tables created.

It turns out that the enterprise installation I am working on has a highly sharded database, and the session tables are not in the same database as the default database.

So to get this to work, I performed the above fake migration steps, and also had to specify the database: --database <session_db>

e.g.

manage.py migrate --database session

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.