Loading django/db/backends/schema.py +5 −3 Original line number Diff line number Diff line Loading @@ -64,6 +64,8 @@ class BaseDatabaseSchemaEditor(object): Marks the start of a schema-altering run. """ self.deferred_sql = [] self.old_autocommit = self.connection.autocommit if self.connection.autocommit: self.connection.set_autocommit(False) def commit(self): Loading @@ -73,7 +75,7 @@ class BaseDatabaseSchemaEditor(object): for sql in self.deferred_sql: self.execute(sql) self.connection.commit() self.connection.set_autocommit(True) self.connection.set_autocommit(self.old_autocommit) def rollback(self): """ Loading @@ -82,7 +84,7 @@ class BaseDatabaseSchemaEditor(object): if not self.connection.features.can_rollback_ddl: raise RuntimeError("Cannot rollback schema changes on this backend") self.connection.rollback() self.connection.set_autocommit(True) self.connection.set_autocommit(self.old_autocommit) # Core utility functions Loading tests/schema/tests.py +1 −1 Original line number Diff line number Diff line Loading @@ -453,7 +453,7 @@ class SchemaTests(TransactionTestCase): Tag.objects.create(title="foo", slug="foo") Tag.objects.create(title="bar", slug="foo") connection.rollback() # Alter the slug field to be non-unique # Alter the slug field to be unique new_new_field = SlugField(unique=True) new_new_field.set_attributes_from_name("slug") editor = connection.schema_editor() Loading Loading
django/db/backends/schema.py +5 −3 Original line number Diff line number Diff line Loading @@ -64,6 +64,8 @@ class BaseDatabaseSchemaEditor(object): Marks the start of a schema-altering run. """ self.deferred_sql = [] self.old_autocommit = self.connection.autocommit if self.connection.autocommit: self.connection.set_autocommit(False) def commit(self): Loading @@ -73,7 +75,7 @@ class BaseDatabaseSchemaEditor(object): for sql in self.deferred_sql: self.execute(sql) self.connection.commit() self.connection.set_autocommit(True) self.connection.set_autocommit(self.old_autocommit) def rollback(self): """ Loading @@ -82,7 +84,7 @@ class BaseDatabaseSchemaEditor(object): if not self.connection.features.can_rollback_ddl: raise RuntimeError("Cannot rollback schema changes on this backend") self.connection.rollback() self.connection.set_autocommit(True) self.connection.set_autocommit(self.old_autocommit) # Core utility functions Loading
tests/schema/tests.py +1 −1 Original line number Diff line number Diff line Loading @@ -453,7 +453,7 @@ class SchemaTests(TransactionTestCase): Tag.objects.create(title="foo", slug="foo") Tag.objects.create(title="bar", slug="foo") connection.rollback() # Alter the slug field to be non-unique # Alter the slug field to be unique new_new_field = SlugField(unique=True) new_new_field.set_attributes_from_name("slug") editor = connection.schema_editor() Loading