[Answered ]-Modifying User instances in Django already in database

2👍

For users already in your database, you can run a script on your django shell.

python manage.py shell

Then:

>>from .models import *
>>from django.contrib.auth.models import User
>>users_without_profile = User.objects.filter(profile__isnull=True)
>>for user in users_without_profile:
....user.profile.nickname = 'your_choice_of_nickname'
....user.save()

Just a side note: doing a wild import like from .models import * is a bad practice, but I did it anyway just for illustration and also I didn’t know you appname. Hence, import the appropriate models from the respective app.

Hope this helps you.

Leave a comment