|
1 | 1 | # Generated by Django 4.1.5 on 2023-02-15 17:52 |
2 | 2 |
|
3 | 3 | from django.db import migrations |
| 4 | +from django.core.exceptions import FieldError |
4 | 5 |
|
5 | 6 |
|
6 | 7 | def forwards_migrate_napalm(apps, schema_editor): |
7 | 8 | Platform = apps.get_model("dcim", "Platform") |
8 | | - NapalmPlatformConfig = apps.get_model("netbox_napalm_plugin", "NapalmPlatformConfig") |
9 | | - qs = Platform.objects.all().exclude(napalm_driver__exact="") |
10 | | - for platform in qs: |
11 | | - NapalmPlatformConfig.objects.create( |
12 | | - platform=platform, |
13 | | - napalm_driver=platform.napalm_driver, |
14 | | - napalm_args=platform.napalm_args, |
15 | | - ) |
| 9 | + try: |
| 10 | + NapalmPlatformConfig = apps.get_model("netbox_napalm_plugin", "NapalmPlatformConfig") |
| 11 | + qs = Platform.objects.all().exclude(napalm_driver__exact="") |
| 12 | + for platform in qs: |
| 13 | + NapalmPlatformConfig.objects.create( |
| 14 | + platform=platform, |
| 15 | + napalm_driver=platform.napalm_driver, |
| 16 | + napalm_args=platform.napalm_args, |
| 17 | + ) |
| 18 | + except FieldError: |
| 19 | + pass |
16 | 20 |
|
17 | 21 |
|
18 | 22 | def reverse_migrate_napalm(apps, schema_editor): |
19 | 23 | Platform = apps.get_model("dcim", "Platform") |
20 | | - NapalmPlatformConfig = apps.get_model("netbox_napalm_plugin", "NapalmPlatformConfig") |
21 | | - qs = Platform.objects.all().exclude(napalm_driver__exact="") |
22 | | - for platform in qs: |
23 | | - NapalmPlatformConfig.objects.delete( |
24 | | - platform=platform, |
25 | | - ) |
| 24 | + try: |
| 25 | + NapalmPlatformConfig = apps.get_model("netbox_napalm_plugin", "NapalmPlatformConfig") |
| 26 | + qs = Platform.objects.all().exclude(napalm_driver__exact="") |
| 27 | + for platform in qs: |
| 28 | + NapalmPlatformConfig.objects.delete( |
| 29 | + platform=platform, |
| 30 | + ) |
| 31 | + except FieldError: |
| 32 | + pass |
26 | 33 |
|
27 | 34 |
|
28 | 35 | class Migration(migrations.Migration): |
|
0 commit comments