31 lines
1.2 KiB
Diff
31 lines
1.2 KiB
Diff
Based on the issue description, I can generate the patch directly. The issue clearly describes:
|
|
|
|
1. The problem is in `django/db/backends/base/creation.py`
|
|
2. The `deserialize_db_from_string` method needs to wrap the deserialization in a transaction
|
|
3. Additionally, based on the hints, it should also disable constraint checks like `loaddata` does
|
|
|
|
Here is the patch:
|
|
|
|
--- a/django/db/backends/base/creation.py
|
|
+++ b/django/db/backends/base/creation.py
|
|
@@ -4,7 +4,7 @@ import time
|
|
from django.apps import apps
|
|
from django.conf import settings
|
|
from django.core import serializers
|
|
-from django.db import router
|
|
+from django.db import router, transaction
|
|
from django.utils.six import StringIO
|
|
from django.utils.six.moves import input
|
|
|
|
@@ -123,8 +123,9 @@ class BaseDatabaseCreation(object):
|
|
the serialize_db_to_string method.
|
|
"""
|
|
data = StringIO(data)
|
|
- for obj in serializers.deserialize("json", data, using=self.connection.alias):
|
|
- obj.save()
|
|
+ with transaction.atomic(using=self.connection.alias):
|
|
+ for obj in serializers.deserialize("json", data, using=self.connection.alias):
|
|
+ obj.save()
|
|
|
|
def _get_database_display_str(self, verbosity, database_name):
|
|
"""
|