code: def pre_migrate(cls, sender=None, **kwargs):
          
          ContentType = apps.get_model('contenttypes', 'ContentType')
          try:
              queryset = ContentType.objects.filter(app_label=sender.label)
              for ctype in queryset.exclude(model__in=sender.get_proxy_models().keys()):
                  model = ctype.model_class()
                  if model is None:
                      sender.revoke_permissions(ctype)
                      ContentType.objects.get(app_label=sender.label, model=ctype).delete()
          except DatabaseError:
              return
docs: Iterate over contenttypes and remove those not in proxy models