यह मेरे डेटा लोडिंग स्क्रिप्ट के शीर्ष पर है।
import string
import sys
try:
import settings # Assumed to be in the same directory.
#settings.DISABLE_TRANSACTION_MANAGEMENT = True
except ImportError:
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
sys.exit(1)
#Setup the django environment with the settings module.
import django
import django.core.management
django.core.management.setup_environ(settings)
from django.db import transaction
यह आपकी स्क्रिप्ट में और कुछ करने से पहले निष्पादित होना चाहिए।
एक और तरीका फिक्स्चर और manage.py का उपयोग करना है। यद्यपि यदि आप डेटाबेस को प्रारंभ करने के लिए थोक डेटा लोड को पूरा करने की कोशिश कर रहे हैं, तो यह ठीक काम करना चाहिए।
इसके अलावा आप जो भी कर रहे हैं उसके आधार पर आप इसे एक लेनदेन में कर सकते हैं या नहीं कर सकते हैं। उपरोक्त लेनदेन लाइन को अनदेखा करें और इसके समान कोड बनाएं।
transaction.enter_transaction_management()
try:
#Do some stuff
transaction.commit()
finally:
transaction.rollback()
pass
transaction.leave_transaction_management()
स्रोत
2008-10-08 21:00:46
जब तक मुझे कुछ याद नहीं आ रहा है, तो प्रबंधन के पास Django 1.0 में एक रनस्क्रिप्ट सबकॉमैंड नहीं है। यदि आप इस कार्यक्षमता को प्रदान करने के लिए कस्टम ऐप का उपयोग कर रहे हैं तो आपको इसका उल्लेख करना चाहिए। –