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 :)
This commit is contained in:
Florian Apolloner 2014-04-21 15:37:12 +02:00
parent a4553e0510
commit 405b13fe83
1 changed files with 2 additions and 2 deletions

View File

@ -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: