pulseapi/users/migrations/0009_auto_20180823_2126.py (37 lines of code) (raw):

# -*- coding: utf-8 -*- # Generated by Django 1.11.14 on 2018-08-23 21:26 from __future__ import unicode_literals from django.apps import apps as global_apps from django.db import migrations from django.core.exceptions import ObjectDoesNotExist def connect_social_accounts_for_users(apps, schema_editor): try: EmailAddress = apps.get_model('allauth.account', 'EmailAddress') SocialAccount = apps.get_model('allauth.socialaccount', 'SocialAccount') except LookupError: # The allauth apps aren't installed. return EmailUser = apps.get_model('users', 'EmailUser') for user in EmailUser.objects.all(): try: EmailAddress.objects.get(email=user.email) except ObjectDoesNotExist: EmailAddress.objects.create( user=user, email=user.email, verified=True, primary=True, ) SocialAccount.objects.create( user=user, provider='google' ) class Migration(migrations.Migration): dependencies = [ ('users', '0008_auto_20170929_1812'), ] if global_apps.is_installed('allauth.account') and global_apps.is_installed('allauth.socialaccount'): dependencies.extend([ ('account', '__latest__'), ('socialaccount', '__latest__'), ]) operations = [ migrations.RunPython(connect_social_accounts_for_users), ]