I'm on Django 1.9, Python 3.6. I made this migration to try and fill in UserProfiles for any users missing them.
But I'm getting the error below.
What's strange is the "user" variable seems to be a User instance.
from __future__ import unicode_literals
from django.db import migrations
from django.contrib.auth.models import User
def create_missing_profiles(apps, schema_editor):
UserProfile = apps.get_model("myapp", "UserProfile")
for user in User.objects.all():
UserProfile.objects.get_or_create(user=user)
class Migration(migrations.Migration):
dependencies = [
('myapp', '0004_auto_20170721_0908'),
]
operations = [
migrations.RunPython(create_missing_profiles),
]
Error:
ValueError: Cannot query "peterson": Must be "User" instance.