E
E
Ernst Krause2019-10-24 10:27:02
Django
Ernst Krause, 2019-10-24 10:27:02

Django.db.utils.IntegrityError. How to correctly specify the username in the model field argument? And how to fix the django.db.utils.IntegrityError error?

I'm trying to add a username to the name field of the Profile model.
models.py

from django import forms
from django.contrib.auth.models import User

class Profile(models.Model):
    name = models.ForeignKey(User, on_delete=models.CASCADE)

After adding, I run makemigrations and migrate migrations. Makemigrations runs fine, but after migrate the console swears
5db151530140b086733268.jpeg
What exactly am I doing wrong? How to fix this error?
I am using SQlite3, Django 2 version

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Tikhonov, 2019-10-25
@tumbler

Where does the title_id column come from? Either you do not show all the code, or you have scraps of experiments in the database. Recreate the database from scratch.

K
Kirill Gorelov, 2019-10-24
@Kirill-Gorelov

I am not using ForeignKey but OneToOneField.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question