Database access in data migrations defaults to the 'default' database. Force it to the user selected database instead.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2018-09-19 20:53:04 -04:00
parent fdfa4755e9
commit eda8d18146
13 changed files with 31 additions and 26 deletions
@@ -8,12 +8,11 @@ def move_content_from_documents_to_ocr_app(apps, schema_editor):
DocumentPage = apps.get_model('documents', 'DocumentPage')
DocumentPageContent = apps.get_model('ocr', 'DocumentPageContent')
for document_page in DocumentPage.objects.all():
document_page_content = DocumentPageContent(
for document_page in DocumentPage.objects.using(schema_editor.connection.alias).all():
document_page_content = DocumentPageContent.objects.using(schema_editor.connection.alias).create(
document_page=document_page,
content=document_page.content_old or ''
)
document_page_content.save()
class Migration(migrations.Migration):
@@ -8,9 +8,11 @@ def create_ocr_setting_for_existing_document_types(apps, schema_editor):
DocumentType = apps.get_model('documents', 'DocumentType')
DocumentTypeSettings = apps.get_model('ocr', 'DocumentTypeSettings')
for document_type in DocumentType.objects.all():
for document_type in DocumentType.objects.using(schema_editor.connection.alias).all():
try:
DocumentTypeSettings.objects.create(document_type=document_type)
DocumentTypeSettings.objects.using(
schema_editor.connection.alias
).create(document_type=document_type)
except DocumentTypeSettings.DoesNotExist:
pass