Django swapped User model creates user_ptr_id

I'm trying to update Django from 2 to 3.2.

We have our user model:

class Agent(User):

    username_validator = ExtendedUnicodeUsernameValidator()

    class Meta:
        ordering = ('id',)

    objects = AgentManager()

    user = models.OneToOneField(
        settings.AUTH_USER_MODEL,
        editable=False,
        related_name='agent',
        on_delete=models.CASCADE,
        parent_link=True,
    )

User model from django makes it swappable:

class User(AbstractUser):
    """
    Users within the Django authentication system are represented by this
    model.

    Username and password are required. Other fields are optional.
    """
    class Meta(AbstractUser.Meta):
        swappable = 'AUTH_USER_MODEL'

I run tests with creating database and get this error:

django.db.utils.IntegrityError: null value in column "user_ptr_id" of relation "staff_agent" violates not-null constraint
DETAIL:  Failing row contains (null, null, 1, null, null, null, null, null, null).

Migrations create new field user_ptr_id, that wasn't creating in Django 2, but dosen't fill it when inserting row.

The question is how to disable creating this field or where django does it.

Вернуться на верх