<commit_before>from django.db import migrations, models


def make_empty_email_field_null(apps, schema_editor):
    Company = apps.get_model('company', 'Company')
    for company in Company.objects.all():
        if company.email == '':
            company.email = None
        company.save()


class Migration(migrations.Migration):

    dependencies = [
        ('company', '0023_auto_20200808_0715'),
    ]

    operations = [
        migrations.RunPython(make_empty_email_field_null),
        migrations.AlterField(
            model_name='company',
            name='email',
            field=models.EmailField(blank=True, help_text='Contact email address', max_length=254, null=True, unique=True, verbose_name='Email'),
        ),
        migrations.AlterField(
            model_name='company',
            name='name',
            field=models.CharField(help_text='Company name', max_length=100, verbose_name='Company name'),
        ),
    ]<commit_msg>Improved migration, still fails if email duplicates exist in current DB<commit_after>from django.db import migrations, models


def make_empty_email_field_null(apps, schema_editor):
    Company = apps.get_model('company', 'Company')
    for company in Company.objects.all():
        if company.email == '':
            company.email = None
            company.save()


class Migration(migrations.Migration):

    dependencies = [
        ('company', '0023_auto_20200808_0715'),
    ]

    operations = [
        # Allow email field to be NULL
        migrations.AlterField(
            model_name='company',
            name='email',
            field=models.EmailField(blank=True, help_text='Contact email address', max_length=254, null=True, unique=False, verbose_name='Email'),
        ),
        # Convert empty email string to NULL
        migrations.RunPython(make_empty_email_field_null),
        # Make email field unique
        migrations.AlterField(
            model_name='company',
            name='email',
            field=models.EmailField(blank=True, help_text='Contact email address', max_length=254, null=True, unique=True, verbose_name='Email'),
        ),
        # Remove unique constraint on name field
        migrations.AlterField(
            model_name='company',
            name='name',
            field=models.CharField(help_text='Company name', max_length=100, verbose_name='Company name'),
        ),
    ]
{'fraction_non_alphanumeric': 0.1103247293921732, 'fraction_numerical': 0.019567027477102414, 'mean_word_length': 2.784251968503937, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3745930', 'n_tokens_mistral': 689, 'n_tokens_neox': 657, 'n_words': 135}