diff --git a/allianceauth/authentication/managers.py b/allianceauth/authentication/managers.py index 292bb57d..b97963a6 100755 --- a/allianceauth/authentication/managers.py +++ b/allianceauth/authentication/managers.py @@ -20,8 +20,6 @@ def available_states_query(character): class CharacterOwnershipManager(Manager): - use_in_migrations = True - def create_by_token(self, token): if not EveCharacter.objects.filter(character_id=token.character_id).exists(): EveCharacter.objects.create_character(token.character_id) diff --git a/allianceauth/authentication/migrations/0015_user_profiles.py b/allianceauth/authentication/migrations/0015_user_profiles.py index 6eb25cb8..f77d3f5a 100644 --- a/allianceauth/authentication/migrations/0015_user_profiles.py +++ b/allianceauth/authentication/migrations/0015_user_profiles.py @@ -107,12 +107,11 @@ def populate_ownerships(apps, schema_editor): tokens = Token.objects.filter(character_id__in=unique_character_owners) for c_id in unique_character_owners: - ts = tokens.filter(character_id=c_id).order_by('created') - for t in ts: - if t.refresh_token: - # find newest refreshable token and use it as basis for CharacterOwnership - CharacterOwnership.objects.create_by_token(t) - break + # find newest refreshable token and use it as basis for CharacterOwnership + ts = tokens.filter(character_id=c_id).exclude(refresh_token__isnull=True).order_by('created') + if ts.exists(): + token = ts[0] + CharacterOwnership.objects.create(user_id=token.user_id, character_id=token.character_id, owner_hash=token.character_owner_hash) def create_profiles(apps, schema_editor):