From 405b13fe83e3d8c9079545429d40c434eb496893 Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Mon, 21 Apr 2014 15:37:12 +0200 Subject: [PATCH] Fixed migrate when called inside a transaction. This is useful for tests manually calling migrate inside a testcase, for normal usage this should make no difference, since there is no surrounding transaction after all. If there is one we still try to leave the transaction in a useable state (for postgres at least). If this commit turns out to be causing issues, settings savepoint=False is probably the right fix :) --- django/core/management/commands/migrate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py index 1ca4ec7957..6f152ffec6 100644 --- a/django/core/management/commands/migrate.py +++ b/django/core/management/commands/migrate.py @@ -204,7 +204,7 @@ class Command(BaseCommand): # Create the tables for each model if self.verbosity >= 1: self.stdout.write(" Creating tables...\n") - with transaction.atomic(using=connection.alias, savepoint=False): + with transaction.atomic(using=connection.alias, savepoint=connection.features.can_rollback_ddl): for app_name, model_list in manifest.items(): for model in model_list: # Create the model's database table, if it doesn't already exist. @@ -264,7 +264,7 @@ class Command(BaseCommand): if self.verbosity >= 2: self.stdout.write(" Installing index for %s.%s model\n" % (app_name, model._meta.object_name)) try: - with transaction.atomic(using=connection.alias): + with transaction.atomic(using=connection.alias, savepoint=connection.features.can_rollback_ddl): for sql in index_sql: cursor.execute(sql) except Exception as e: