mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Improved migration, still fails if email duplicates exist in current DB
This commit is contained in:
parent
ac82640c6c
commit
70a3b7f891
@ -6,7 +6,7 @@ def make_empty_email_field_null(apps, schema_editor):
|
|||||||
for company in Company.objects.all():
|
for company in Company.objects.all():
|
||||||
if company.email == '':
|
if company.email == '':
|
||||||
company.email = None
|
company.email = None
|
||||||
company.save()
|
company.save()
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
@ -16,12 +16,21 @@ class Migration(migrations.Migration):
|
|||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
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),
|
migrations.RunPython(make_empty_email_field_null),
|
||||||
|
# Make email field unique
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='company',
|
model_name='company',
|
||||||
name='email',
|
name='email',
|
||||||
field=models.EmailField(blank=True, help_text='Contact email address', max_length=254, null=True, unique=True, verbose_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(
|
migrations.AlterField(
|
||||||
model_name='company',
|
model_name='company',
|
||||||
name='name',
|
name='name',
|
||||||
|
Loading…
Reference in New Issue
Block a user