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:
parent
a4553e0510
commit
405b13fe83
|
@ -204,7 +204,7 @@ class Command(BaseCommand):
|
||||||
# Create the tables for each model
|
# Create the tables for each model
|
||||||
if self.verbosity >= 1:
|
if self.verbosity >= 1:
|
||||||
self.stdout.write(" Creating tables...\n")
|
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 app_name, model_list in manifest.items():
|
||||||
for model in model_list:
|
for model in model_list:
|
||||||
# Create the model's database table, if it doesn't already exist.
|
# Create the model's database table, if it doesn't already exist.
|
||||||
|
@ -264,7 +264,7 @@ class Command(BaseCommand):
|
||||||
if self.verbosity >= 2:
|
if self.verbosity >= 2:
|
||||||
self.stdout.write(" Installing index for %s.%s model\n" % (app_name, model._meta.object_name))
|
self.stdout.write(" Installing index for %s.%s model\n" % (app_name, model._meta.object_name))
|
||||||
try:
|
try:
|
||||||
with transaction.atomic(using=connection.alias):
|
with transaction.atomic(using=connection.alias, savepoint=connection.features.can_rollback_ddl):
|
||||||
for sql in index_sql:
|
for sql in index_sql:
|
||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Reference in New Issue