U'id 'django model collides when using OneToOneField

I created a UserProfile model to link the User model.

I got an error while executing python manage.py makemigrations:

django.core.exceptions.FieldError: the local field u'id 'in the class' UserProfile' collides with a field of the same name from the base class' User '

Here is the code:

from django.contrib.auth.models import User from django.db.models.signals import post_save class UserProfile(models.Model): user = models.OneToOneField(User, related_name='user_of') description = models.TextField() def create_user_profile(sender, instance, created, **kwargs): if created: profile, created = UserProfile.objects.get_or_create(user=instance) post_save.connect(create_user_profile, sender=User) 

Environment: Django 1.8.2, Python 2.7.6, PostgreSQL 9.4.2

This is mistake? How did it happen that the u'id 'from' UserProfile 'encounters a "User" error ...

I tried adding a line to the settings.py file:

 AUTH_PROFILE_MODULE = 'user_profile.UserProfile' 

But it did not help whether it was or not.

How to fix it? Thanks!

+6
source share
1 answer

You probably have an old migration that was used to inherit from the model in question.

To verify this, clone your project and delete all migrations and makemigrations in the new new database

If it works, then track the redirect from your current project and remember to also remove the entry from the django_migrations table

+7
source

Source: https://habr.com/ru/post/987954/


All Articles