V
V
vikholodov2018-09-14 14:15:52
Django
vikholodov, 2018-09-14 14:15:52

How to fix already exists error on load data?

I made a dump with sqllite, --exclude auth.permission --exclude contenttypes, everything is as it should be.
I built pgsql on the server, I do load data, and it crashes:

Could not load accounts.UserProfile(pk=1): duplicate key value violates unique constraint "accounts_userprofile_user_id_key"
DETAIL:  Key (user_id)=(1) already exists.

I tried to kill all migrations, made new migrations, the database is empty, I didn’t add anything there, I do load data, the same garbage. For the sake of experiment, he deleted the entry on which he swears from the dump, as expected, he began to swear at pk=2.
Ok, googled, found magic mega command ./manage.py sqlsequencereset app1 app2, didn't help. What could be the problem?
the UserProfile model is something like this:
class UserProfile(models.Model):
    user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    avatar = models.ImageField(blank=True, upload_to='user_avatar')
    ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2018-09-14
@vikholodov

I suspect, but not sure, that when you create the User model, you automatically create a UserProfile on a signal. In general, creating a profile in this way has been outdated for 5-6 years already. It has long been necessary to switch to using your own user model, in which to add the missing fields.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question