[Solved]-Multiple default values specified for column "id" of the table


Try explicitly specifying the id field and marking it as the primary key:

class UserProfile(models.Model):
    id = models.BigIntegerField(primary_key = True)
    user = models.OneToOneField(User)
    avatar = models.ImageField(blank=True, upload_to=get_image_path, default='/static/image/avatar/male.png')
    age = models.IntegerField(default=4, validators=[MinValueValidator(3), MaxValueValidator(99)])

Django should automatically create a sequence for this field.

It may be that the User foreign key without an explicitly defined primary key is confusing the ORM, although that’s just a theory.


If you are developing locally, and don’t care about your migration history, and you just need a quick-fix, you could do this:

manage.py migrate <your app name> zero

Then delete the migration files except for the __init__.py in <your app name>.


manage.py makemigrations <your app name>
manage.py migrate

A more complicated approach would be learning how to write and modify migration files to populate existing rows.


Leave a comment