ensure reverse migration to delete a specific row won’t fail.
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import logging
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.db import migrations
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def add_service_user(apps, schema_editor):
|
||||
"""Add service user."""
|
||||
user, created = User.objects.get_or_create(username=settings.CREDENTIALS_SERVICE_USERNAME)
|
||||
@@ -20,8 +24,9 @@ def remove_service_user(apps, schema_editor):
|
||||
"""Remove service user."""
|
||||
try:
|
||||
User.objects.get(username=settings.CREDENTIALS_SERVICE_USERNAME).delete()
|
||||
except User.DoesNotExist:
|
||||
return
|
||||
except Exception: # pylint: disable=broad-except
|
||||
logger.exception('Unexpected error while attempting to delete credentials service user.')
|
||||
logger.warning('This service user account may need cleanup, but migrations can safely continue.')
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
Reference in New Issue
Block a user