From f54cf28ff75909fc63ac0135df36f2c5ad72fbf3 Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Thu, 19 Nov 2020 12:06:20 +0100 Subject: [PATCH] Make migration 0020 multi-database friendly --- django_mercadopago/migrations/0002_auto_20150923_2328.py | 7 ++++++- .../migrations/0020_move_preference_items.py | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/django_mercadopago/migrations/0002_auto_20150923_2328.py b/django_mercadopago/migrations/0002_auto_20150923_2328.py index 48b32be..559a210 100644 --- a/django_mercadopago/migrations/0002_auto_20150923_2328.py +++ b/django_mercadopago/migrations/0002_auto_20150923_2328.py @@ -4,6 +4,7 @@ def fake_data(apps, schema_editor): db_alias = schema_editor.connection.alias + Account = apps.get_model("mp", "Account") Notification = apps.get_model("mp", "Notification") Payment = apps.get_model("mp", "Payment") @@ -18,7 +19,11 @@ def fake_data(apps, schema_editor): return account = Account.objects.using(db_alias).create( - name="Auto-migrated", slug="_", app_id="_", secret_key="_", sandbox=True, + name="Auto-migrated", + slug="_", + app_id="_", + secret_key="_", + sandbox=True, ) Notification.objects.using(db_alias).update(owner=account) diff --git a/django_mercadopago/migrations/0020_move_preference_items.py b/django_mercadopago/migrations/0020_move_preference_items.py index 0e2791f..30e9836 100644 --- a/django_mercadopago/migrations/0020_move_preference_items.py +++ b/django_mercadopago/migrations/0020_move_preference_items.py @@ -3,11 +3,13 @@ def move_item_data(apps, schema_editor): """Move Item data from Preference into the new model.""" + db_alias = schema_editor.connection.alias + Preference = apps.get_model("mp", "Preference") Item = apps.get_model("mp", "Item") - for preference in Preference.objects.all(): - Item.objects.create( + for preference in Preference.objects.using(db_alias).all(): + Item.objects.using(db_alias).create( preference=preference, title=preference.title, description=preference.description,