diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index 346d10198d..68551aad51 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -269,6 +269,8 @@ class BaseDatabaseWrapper(object): """ self.validate_no_atomic_block() + self.ensure_connection() + self.transaction_state.append(managed) if not managed and self.is_dirty() and not forced: @@ -286,6 +288,8 @@ class BaseDatabaseWrapper(object): """ self.validate_no_atomic_block() + self.ensure_connection() + if self.transaction_state: del self.transaction_state[-1] else: