#4721: Tweak migrations to ensure Interface.device cannot be null

This commit is contained in:
Jeremy Stretch 2020-07-02 13:12:37 -04:00
parent 1f9cdc71d4
commit 6abb7e8f4d
2 changed files with 11 additions and 5 deletions

View File

@ -1,6 +1,5 @@
# Generated by Django 3.0.6 on 2020-06-22 16:03
from django.db import migrations
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
@ -15,4 +14,11 @@ class Migration(migrations.Migration):
model_name='interface',
name='virtual_machine',
),
# device is now a required field
migrations.AlterField(
model_name='interface',
name='device',
field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, related_name='interfaces', to='dcim.Device'),
preserve_default=False,
),
]

View File

@ -51,8 +51,8 @@ def replicate_interfaces(apps, schema_editor):
# Verify that all interfaces have been replicated
assert replicated_count == original_interfaces.count(), "Replicated interfaces count does not match original count!"
# Delete original VM interfaces
original_interfaces.delete()
# Delete all interfaces not assigned to a Device
Interface.objects.filter(device__isnull=True).delete()
class Migration(migrations.Migration):