Correct way to extend AbstractUser in Django?
<p>I'm trying to integrate two django apps where each had their individual auths working. To do that, I'm trying to subclass AbstractUser instead of User. I'm following the <a href="https://pybbm.readthedocs.io/en/latest/customuser.html" rel="nofollow">PyBB docs</a> and <a href="https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#substituting-a-custom-user-model" rel="nofollow">Django#substituting_custom_model</a>. I've removed all migration files in all my apps apart from their individual <strong>init</strong>.py (including the migrations from the PyBB library sitting in my site-packages). I've also changed the Mysql database to a blank one to start afresh and I'm trying to subclass AbstractUser as shown below. </p>

<p>My Models.py:</p>

<pre><code>from django.contrib.auth.models import User
from django.contrib.auth.models import AbstractUser

from django.db import models
class Student_User(models.Model):
    """
    Table to store accounts
    """
    su_student = models.OneToOneField(AbstractUser)

    USERNAME_FIELD = 'su_student'

    su_type = models.PositiveSmallIntegerField(db_column='su_type', default=0)
    su_access = models.TextField(db_column='su_access', default='')
    su_packs = models.TextField(db_column='su_packs', default='')

    REQUIRED_FIELDS = []

    def __unicode__(self):
        return str(self.su_student)
</code></pre>

<p>My settings.py:</p>

<pre><code>AUTH_USER_MODEL = "app.Student_User"
PYBB_PROFILE_RELATED_NAME = 'pybb_profile'
</code></pre>

<p>When running makemigrations for my primary app, I get this error:</p>

<pre><code>app.Student_User.su_student: (fields.E300) Field defines a relation with model 'AbstractUser', which is either not installed, or is abstract.
</code></pre>

<p>How do I achieve what I am trying to do here? </p>

<p>PS: The app was working fine with onetoone with User without username_field or required_field.</p>

<p>PPS: I just checked the AbstractUser model in my contrib.auth.models and it has <code>class Meta: abstract = True</code>. Ok so its abstract, still, how do I resolve this? I just need one login, currently, two parts of my site, although connected through urls, ask for seperate logins and dont detect each others logins. What do I need to do for this?</p>

<p>You can't have a one-to-one relationship with an abstract model; by definition, an abstract model is never actually instantiated.</p>

<p>AbstractUser is supposed to be <em>inherited</em>. Your structure should be:</p>

<pre><code>class Student_User(AbstractUser):
    ...
</code></pre>

python mysql django authorization django-authentication