diff --git a/mayan/apps/documents/south_migrations/0022_set_doc_type.py b/mayan/apps/documents/south_migrations/0022_set_doc_type.py index 26e0188f4b..b3a4f486be 100644 --- a/mayan/apps/documents/south_migrations/0022_set_doc_type.py +++ b/mayan/apps/documents/south_migrations/0022_set_doc_type.py @@ -5,6 +5,15 @@ from south.v2 import DataMigration from django.db import models +def fake_get_or_create(model, *args, **kwargs): + try: + obj = model.objects.get(**kwargs) + except model.DoesNotExist: + obj = model(**kwargs) + obj.save() + return obj + + class Migration(DataMigration): def forwards(self, orm): @@ -12,7 +21,7 @@ class Migration(DataMigration): # Note: Don't use "from appname.models import ModelName". # Use orm.ModelName to refer to models in this application, # and orm['appname.ModelName'] for models in other applications. - orphan_doc_type, created = orm.DocumentType.objects.get_or_create(name='_orphan_document_') + orphan_doc_type = fake_get_or_create(orm.DocumentType, name='_orphan_document_') orm.Document.objects.filter(document_type__isnull=True).update(document_type=orphan_doc_type) def backwards(self, orm): diff --git a/mayan/apps/sources/south_migrations/0007_set_doc_type.py b/mayan/apps/sources/south_migrations/0007_set_doc_type.py index 5ef26230a5..a75f6a4606 100644 --- a/mayan/apps/sources/south_migrations/0007_set_doc_type.py +++ b/mayan/apps/sources/south_migrations/0007_set_doc_type.py @@ -5,6 +5,15 @@ from south.v2 import DataMigration from django.db import models +def fake_get_or_create(model, *args, **kwargs): + try: + obj = model.objects.get(**kwargs) + except model.DoesNotExist: + obj = model(**kwargs) + obj.save() + return obj + + class Migration(DataMigration): def forwards(self, orm): @@ -12,7 +21,7 @@ class Migration(DataMigration): # Note: Don't use "from appname.models import ModelName". # Use orm.ModelName to refer to models in this application, # and orm['appname.ModelName'] for models in other applications. - orphan_doc_type, created = orm['documents.DocumentType'].objects.get_or_create(name='_orphan_document_') + orphan_doc_type = fake_get_or_create(orm['documents.DocumentType'], name='_orphan_document_') orm.IntervalBaseModel.objects.filter(document_type__isnull=True).update(document_type=orphan_doc_type) def backwards(self, orm):