diff --git a/django/core/management/commands/flush.py b/django/core/management/commands/flush.py index 82dd246160ff..5fde7f7fe459 100644 --- a/django/core/management/commands/flush.py +++ b/django/core/management/commands/flush.py @@ -63,11 +63,18 @@ def handle_noargs(self, **options): if confirm == 'yes': try: - with transaction.atomic(using=database, - savepoint=connection.features.can_rollback_ddl): + + if connection.features.atomic_transactions: + with transaction.atomic(using=database, + savepoint=connection.features.can_rollback_ddl): + cursor = connection.cursor() + for sql in sql_list: + cursor.execute(sql) + else: cursor = connection.cursor() for sql in sql_list: cursor.execute(sql) + except Exception as e: new_msg = ( "Database %s couldn't be flushed. Possible reasons:\n"