diff --git a/InvenTree/company/migrations/0024_unique_name_email_constraint.py b/InvenTree/company/migrations/0024_unique_name_email_constraint.py index 3a8781f98d..e6d1fd93dd 100644 --- a/InvenTree/company/migrations/0024_unique_name_email_constraint.py +++ b/InvenTree/company/migrations/0024_unique_name_email_constraint.py @@ -1,6 +1,14 @@ from django.db import migrations, models +def reverse_empty_email(apps, schema_editor): + Company = apps.get_model('company', 'Company') + for company in Company.objects.all(): + if company.email == None: + company.email = '' + company.save() + + def make_empty_email_field_null(apps, schema_editor): Company = apps.get_model('company', 'Company') for company in Company.objects.all(): @@ -23,7 +31,7 @@ class Migration(migrations.Migration): 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), + migrations.RunPython(make_empty_email_field_null, reverse_code=reverse_empty_email), # Remove unique constraint on name field migrations.AlterField( model_name='company',