[Django]-Django migration cannot assign User instance to user field

4👍

Turns out that calling get_user_model() is not correct to use in the migration. Which is, if you think about it, logical. Since you should never import the models directly in migrations. However the migration error threw me off, complaining that it was expecting a User and not a User. Also the fact that using the get_user_model() function is a little different than importing it directly (i.e. what if you use a different User model).

The way to resolve this is to import the User model from apps:

User = apps.get_model('auth', 'User')

After this the migration went fine.

👤Bono

Leave a comment