R
R
Rassul Nassyrov2020-09-19 11:27:45
Django
Rassul Nassyrov, 2020-09-19 11:27:45

What is wrong with the form?

Mistake:

return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: UNIQUE constraint failed: user_user.username


Models.py:
class User(AbstractUser):
    country = models.CharField(max_length=35, null = True, blank = True)
    city = models.CharField(max_length=35, null = True, blank = True)
    bio = models.CharField(max_length=150, null = True, blank = True)
    image = models.ImageField(upload_to = 'static/images', blank = True)

    def __str__(self):
        return self.username

class UserSettingsForm(ModelForm):
    User = get_user_model()
    class Meta:
        model = User
        fields = ['image']


Views.py:

imgform = UserSettingsForm(request.POST, request.FILES)
                if imgform.is_valid():
                    imgform.save()
                    return redirect('/user/profile')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-09-19
@bacon

1. there is already a record in the database with the same username
2. always show the full traceback of the error
3. stop giving questions the heading "What's wrong with the form?" and the like, it should contain a brief description of the problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question