mirror of
https://github.com/netbox-community/netbox.git
synced 2026-05-06 22:12:43 +08:00
feat(virtualization): use native unique constraint for VirtualMachineType slug (#21970)
Replace the UniqueConstraint on the slug field with the native `unique=True` parameter on SlugField in both the model definition and migration. This resolves a compatibility issue with netbox_branching, which does not handle a SlugField combined with a separate UniqueConstraint on the same field.
This commit is contained in:
@@ -30,7 +30,7 @@ class Migration(migrations.Migration):
|
||||
('description', models.CharField(blank=True, max_length=200)),
|
||||
('comments', models.TextField(blank=True)),
|
||||
('name', models.CharField(max_length=100)),
|
||||
('slug', models.SlugField(max_length=100)),
|
||||
('slug', models.SlugField(max_length=100, unique=True)),
|
||||
(
|
||||
'default_vcpus',
|
||||
models.DecimalField(
|
||||
@@ -95,12 +95,4 @@ class Migration(migrations.Migration):
|
||||
violation_error_message='Virtual machine type name must be unique.',
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='virtualmachinetype',
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=('slug',),
|
||||
name='virtualization_virtualmachinetype_unique_slug',
|
||||
violation_error_message='Virtual machine type slug must be unique.',
|
||||
),
|
||||
),
|
||||
]
|
||||
|
||||
@@ -43,6 +43,7 @@ class VirtualMachineType(ImageAttachmentsMixin, PrimaryModel):
|
||||
slug = models.SlugField(
|
||||
verbose_name=_('slug'),
|
||||
max_length=100,
|
||||
unique=True,
|
||||
)
|
||||
default_platform = models.ForeignKey(
|
||||
to='dcim.Platform',
|
||||
@@ -86,11 +87,6 @@ class VirtualMachineType(ImageAttachmentsMixin, PrimaryModel):
|
||||
name='%(app_label)s_%(class)s_unique_name',
|
||||
violation_error_message=_('Virtual machine type name must be unique.'),
|
||||
),
|
||||
models.UniqueConstraint(
|
||||
fields=('slug',),
|
||||
name='%(app_label)s_%(class)s_unique_slug',
|
||||
violation_error_message=_('Virtual machine type slug must be unique.'),
|
||||
),
|
||||
)
|
||||
indexes = (
|
||||
models.Index(fields=('name',)), # Default ordering
|
||||
|
||||
Reference in New Issue
Block a user