[Answer]-Manually setting user_id when extending User in Django 1.5?

1👍

You need to save the base_user first for it to have an pk (it’s generated by the database).

base_user = User(username =  'username', password = 'password', email = 'user@mail.com')
assert base_user.pk is None  # Of course that's not required, just here to prove the point.
base_user.save()
extended_user = ExtendedUser(user = base_user, ...#other fields#)

But even better,

base_user = User.objects.create(username= 'username', password='password', email='user@mail.com')
extended_user = ExtendedUser.objects.create(user=base_user, #...)

Leave a comment