From 70a3b7f8913cb35f81513ee778c92cf684af2c04 Mon Sep 17 00:00:00 2001 From: eeintech Date: Tue, 13 Oct 2020 07:43:57 -0500 Subject: [PATCH] Improved migration, still fails if email duplicates exist in current DB --- .../company/migrations/0024_auto_20201012_2238.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/InvenTree/company/migrations/0024_auto_20201012_2238.py b/InvenTree/company/migrations/0024_auto_20201012_2238.py index 8066ea960d..32ca981e3b 100644 --- a/InvenTree/company/migrations/0024_auto_20201012_2238.py +++ b/InvenTree/company/migrations/0024_auto_20201012_2238.py @@ -6,7 +6,7 @@ def make_empty_email_field_null(apps, schema_editor): for company in Company.objects.all(): if company.email == '': company.email = None - company.save() + company.save() class Migration(migrations.Migration): @@ -16,12 +16,21 @@ class Migration(migrations.Migration): ] 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',