mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-14 15:52:18 -06:00
Closes #17761: Store empty CharField choices as null
This commit is contained in:
49
netbox/vpn/migrations/0006_charfield_null_choices.py
Normal file
49
netbox/vpn/migrations/0006_charfield_null_choices.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def set_null_values(apps, schema_editor):
|
||||
"""
|
||||
Replace empty strings with null values.
|
||||
"""
|
||||
IKEPolicy = apps.get_model('vpn', 'IKEPolicy')
|
||||
IKEProposal = apps.get_model('vpn', 'IKEProposal')
|
||||
IPSecProposal = apps.get_model('vpn', 'IPSecProposal')
|
||||
|
||||
IKEPolicy.objects.filter(mode='').update(mode=None)
|
||||
IKEProposal.objects.filter(authentication_algorithm='').update(authentication_algorithm=None)
|
||||
IPSecProposal.objects.filter(authentication_algorithm='').update(authentication_algorithm=None)
|
||||
IPSecProposal.objects.filter(encryption_algorithm='').update(encryption_algorithm=None)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('vpn', '0005_rename_indexes'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='ikepolicy',
|
||||
name='mode',
|
||||
field=models.CharField(blank=True, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='ikeproposal',
|
||||
name='authentication_algorithm',
|
||||
field=models.CharField(blank=True, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='ipsecproposal',
|
||||
name='authentication_algorithm',
|
||||
field=models.CharField(blank=True, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='ipsecproposal',
|
||||
name='encryption_algorithm',
|
||||
field=models.CharField(blank=True, null=True),
|
||||
),
|
||||
migrations.RunPython(
|
||||
code=set_null_values,
|
||||
reverse_code=migrations.RunPython.noop
|
||||
),
|
||||
]
|
||||
@@ -35,7 +35,8 @@ class IKEProposal(PrimaryModel):
|
||||
authentication_algorithm = models.CharField(
|
||||
verbose_name=_('authentication algorithm'),
|
||||
choices=AuthenticationAlgorithmChoices,
|
||||
blank=True
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
group = models.PositiveSmallIntegerField(
|
||||
verbose_name=_('group'),
|
||||
@@ -76,7 +77,8 @@ class IKEPolicy(PrimaryModel):
|
||||
mode = models.CharField(
|
||||
verbose_name=_('mode'),
|
||||
choices=IKEModeChoices,
|
||||
blank=True
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
proposals = models.ManyToManyField(
|
||||
to='vpn.IKEProposal',
|
||||
@@ -128,12 +130,14 @@ class IPSecProposal(PrimaryModel):
|
||||
encryption_algorithm = models.CharField(
|
||||
verbose_name=_('encryption'),
|
||||
choices=EncryptionAlgorithmChoices,
|
||||
blank=True
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
authentication_algorithm = models.CharField(
|
||||
verbose_name=_('authentication'),
|
||||
choices=AuthenticationAlgorithmChoices,
|
||||
blank=True
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
sa_lifetime_seconds = models.PositiveIntegerField(
|
||||
verbose_name=_('SA lifetime (seconds)'),
|
||||
|
||||
Reference in New Issue
Block a user