0

It is my first time encountered this error, I've implemented it multiple times on my different projects and migrated to database it works fine , but just this one returns me an error, when I tried to migrate my models.py it says:

django.db.utils.IntegrityError: (1215, 'Cannot add foreign key constraint')

Now I have UserDetails class which linked to the AuthUser of Django migration I tried it multiple times in previous projects but this one has an error, I don't know the real issue here. it is my version of Python? mysql?

class AuthUser(models.Model):         //comes from the command : python manage.py inspectdb > models.py
    password = models.CharField(max_length=128)
    last_login = models.DateTimeField(blank=True, null=True)
    is_superuser = models.IntegerField()
    username = models.CharField(unique=True, max_length=150)
    first_name = models.CharField(max_length=150)
    last_name = models.CharField(max_length=150)
    email = models.CharField(max_length=254)
    is_staff = models.IntegerField()
    is_active = models.IntegerField()
    date_joined = models.DateTimeField()

    class Meta:
        managed = False
        db_table = 'auth_user'

class UserDetails(models.Model):
    user_id = models.OneToOneField(AuthUser, on_delete=models.CASCADE)
    middle_name = models.CharField(max_length=128, blank=True, null=True)
    birthdate = models.DateField(blank=True, null=True)
    sex = models.CharField(max_length=128, blank=True, null=True)
    address = models.CharField(max_length=128, blank=True, null=True)
    position = models.CharField(max_length=128, blank=True, null=True)
    updated_at = models.DateTimeField(blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'user_details'

0 Answers0