12👍
✅
You can do something like:
def add_user(apps, schema_editor):
apps.get_model('myapp', 'Foo').objects.filter(user_id=1).update(
user=apps.get_model('auth', 'User').objects.create_user(username='anonymous')
)
This works because in this case “no type is checked”, the query will use a reference to the entry in the DB instead: the ID of the user.
Source:stackexchange.com