From 6a7d909757bd339db30a58989ddd3e23fd1db683 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 28 Nov 2023 07:59:12 -0500 Subject: [PATCH] Extend migration to update content types --- netbox/ipam/migrations/0068_move_l2vpn.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/netbox/ipam/migrations/0068_move_l2vpn.py b/netbox/ipam/migrations/0068_move_l2vpn.py index 292096f36..b1a059de1 100644 --- a/netbox/ipam/migrations/0068_move_l2vpn.py +++ b/netbox/ipam/migrations/0068_move_l2vpn.py @@ -1,6 +1,19 @@ from django.db import migrations +def update_content_types(apps, schema_editor): + ContentType = apps.get_model('contenttypes', 'ContentType') + + # Delete the new ContentTypes effected by the new models in the vpn app + ContentType.objects.filter(app_label='vpn', model='l2vpn').delete() + ContentType.objects.filter(app_label='vpn', model='l2vpntermination').delete() + + # Update the app labels of the original ContentTypes for ipam.L2VPN and ipam.L2VPNTermination to ensure + # that any foreign key references are preserved + ContentType.objects.filter(app_label='ipam', model='l2vpn').update(app_label='vpn') + ContentType.objects.filter(app_label='ipam', model='l2vpntermination').update(app_label='vpn') + + class Migration(migrations.Migration): dependencies = [ @@ -44,4 +57,8 @@ class Migration(migrations.Migration): ), ], ), + migrations.RunPython( + code=update_content_types, + reverse_code=migrations.RunPython.noop + ), ]