Muhammad Asim
Muhammad Asim

Reputation: 13

Exception: invalid literal for int() with base 10: ''

I am using model for keeping user info like profile picture and bio etc, but when i am signing up this error occurs. Here is the code

class UserProfile(models.Model):
    user = models.OneToOneField(User, on_delete='CASCADE')
    description = models.CharField(max_length = 500, default='', blank = True)
    city = models.CharField(max_length = 100, default='', blank = True)
    website = models.URLField(default='', blank = True)
    phone = models.IntegerField(default='', blank = True)
    image = models.FileField()

@receiver(post_save, sender = User)
def create_profile(sender, instance, created, **kwargs):
        if created:
            UserProfile.objects.create(user=instance)
        instance.userprofile.save()

Upvotes: 1

Views: 103

Answers (1)

chris
chris

Reputation: 2863

invalid literal for int() with base 10: ''

means that can not do Type Conversion on ''.

I suppose phone = models.IntegerField(default='', blank = True) is the question.

Because you don't assign a value to phone, so it uses default value '', which can not be converted by int() in python.

Upvotes: 0

Related Questions