Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 1.8 RC1: ProgrammingError when creating database tables

I'm using AbstractBaseUser for my user models in various projects. Updating to Django 1.8 RC1 works smoothly and I can run the migrate management command. However, when trying to create a fresh database table layout from scratch, I get the following error:

python manage.py migrate
>>> ...
>>> ...
>>> django.db.utils.ProgrammingError: relation "auth_group" does not exist

All works perfectly with Django 1.7.x and I cannot find anything about this issue elsewhere. So, is it a big with the RC1 version or did something change that I'm not aware of in Django 1.8? Unfortunately, the error message doesn't really help ... but I'm pretty sure it has to do with the automatic migrations that come with the new Django version.

like image 560
Simon Steinberger Avatar asked Mar 22 '15 12:03

Simon Steinberger


3 Answers

To copy the answer I got from the Django ticket mentioned above: Before calling "python manage.py migrate" to create the database layout, one needs to create a migration for the app that contains the custom user class:

python manage.py makemigrations appname

This creates a migration file within the app directory - et voilà, migrate does work and creates the other tables.

like image 154
Simon Steinberger Avatar answered Nov 09 '22 00:11

Simon Steinberger


I faced a very similar issue, complaining about relation "auth_group" does not exist however with Django 1.10.

The python manage.py makemigrations appname did not help me as well.

Even the python manage.py showmigrations was not working either, both of them raised the same error.

After examining the traceback in detail, I found out, that in one of my class-based views I was defining the queryset class variable in the following way:

Class SomeClassBasedView(ListView):
    queryset = User.objects.filter(groups=Group.objects.get(name='Tester'))

After changing this to override the get_queryset function intead, it was working properly.

Class SomeClassBasedView(ListView):
     def get_queryset(self):
         return User.objects.filter(groups=Group.objects.get(name='Tester'))
like image 31
Lepi Avatar answered Nov 08 '22 22:11

Lepi


I'm using:

./manage.py makemigrations

then

./manage.py migrate auth

and then

./manage.py migrate
like image 23
Nick Korolkov Avatar answered Nov 08 '22 22:11

Nick Korolkov