2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 04:55:44 +00:00

ignore TOTP migration if the model is not laoded

This commit is contained in:
Matthias Mair
2024-04-08 20:40:39 +02:00
parent 22cc1488d2
commit e7b7d03d14

View File

@ -2,7 +2,7 @@
import base64 import base64
from django.db import migrations from django.db import OperationalError, migrations
from allauth.mfa.adapter import get_adapter from allauth.mfa.adapter import get_adapter
from allauth.mfa.models import Authenticator from allauth.mfa.models import Authenticator
@ -13,6 +13,13 @@ from django_otp.plugins.otp_totp.models import TOTPDevice
def move_mfa(apps, schema_editor): def move_mfa(apps, schema_editor):
"""Data migration to switch to django-allauth's new built-in MFA.""" """Data migration to switch to django-allauth's new built-in MFA."""
adapter = get_adapter() adapter = get_adapter()
try:
TOTPDevice.objects.all().count()
except OperationalError:
# The table may not exist
print('Skipping totp migration as model does not exist')
return
authenticators = [] authenticators = []
for totp in TOTPDevice.objects.filter(confirmed=True).iterator(): for totp in TOTPDevice.objects.filter(confirmed=True).iterator():
recovery_codes = set() recovery_codes = set()