diff --git a/bda/migrations/0004_add_tirage_switch.py b/bda/migrations/0004_add_tirage_switch.py index 1f566b6d..7429197b 100644 --- a/bda/migrations/0004_add_tirage_switch.py +++ b/bda/migrations/0004_add_tirage_switch.py @@ -4,14 +4,17 @@ from __future__ import unicode_literals from django.db import migrations, models from django.utils import timezone + def forwards_func(apps, schema_editor): Tirage = apps.get_model("bda", "Tirage") db_alias = schema_editor.connection.alias - for tirage in Tirage.objects.all(): - tirage.tokens = "Before %s\n\"\"\"%s\"\"\"\n" % ( - timezone.now().strftime("%y-%m-%d %H:%M:%S"), - tirage.tokens) - tirage.save() + for tirage in Tirage.objects.using(db_alias).all(): + if tirage.tokens: + tirage.tokens = "Before %s\n\"\"\"%s\"\"\"\n" % ( + timezone.now().strftime("%y-%m-%d %H:%M:%S"), + tirage.tokens) + tirage.save() + class Migration(migrations.Migration):