Django 1.8 RC1: ProgrammingError when creating database tables

前端 未结 4 2187
离开以前
离开以前 2020-12-16 16:03

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 try

相关标签:
4条回答
  • 2020-12-16 16:06

    I've faced almost the same issue with Django 1.8, solved it only by running manage.py makemigrations app_name for the app with custom User model (+read below)

    e.g.:

    # some_app/models.py:
    from django.contrib.auth.models import AbstractUser
    
    
    class User(AbstractUser):
        pass
    

    AND FOR EVERY app that contained ForeignKey, OneToOneField etc references to it, e.g.:

    # another_app/models.py:
    from django.conf import settings
    from django.db import models
    
    
    class Profile(models.Model):
        user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    

    then manage.py migrate worked with no errors

    the same approach works for any app containing extensions to django.contrib models, e.g. FlatPages etc...

    0 讨论(0)
  • 2020-12-16 16:13

    I'm using:

    ./manage.py makemigrations
    

    then

    ./manage.py migrate auth
    

    and then

    ./manage.py migrate
    
    0 讨论(0)
  • 2020-12-16 16:26

    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.

    0 讨论(0)
  • 2020-12-16 16:28

    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'))
    
    0 讨论(0)
提交回复
热议问题