What are Django database migrations and how do you safely run them in a zero-downtime deployment? Django डेटाबेस माइग्रेशन्स क्या हैं और ज़ीरो-डाउनटाइम डिप्लॉयमेंट में इन्हें सुरक्षित रूप से कैसे चलाएँ?
Migrations are Django's version-controlled way of evolving the database schema to match model changes over time, generated with makemigrations and applied with migrate; each migration file is a Python module describing schema operations that Django can apply forward or, in many cases, roll back.
In a zero-downtime deployment with multiple running instances, migrations must be backward-compatible during the rollout window: old code and new code briefly run side-by-side against the same database, so a migration that drops a column the old code still reads will break the old instances before they're replaced. The safe pattern is splitting risky changes into multiple deploys — add the new column as nullable first, deploy code that writes to both old and new fields, backfill data, then only remove the old field in a later deploy once no running code depends on it.
python manage.py makemigrations
python manage.py migrate --planमाइग्रेशन्स Django का वर्जन-नियंत्रित तरीका है जिससे डेटाबेस स्कीमा को समय के साथ मॉडल बदलावों से मेल खाने के लिए विकसित किया जाता है, makemigrations से जनरेट किया जाता है और migrate से लागू किया जाता है।
कई चल रहे इंस्टेंस वाले ज़ीरो-डाउनटाइम डिप्लॉयमेंट में, माइग्रेशन्स बैकवर्ड-कम्पैटिबल होने चाहिए। सुरक्षित पैटर्न जोखिम भरे बदलावों को कई डिप्लॉयों में विभाजित करना है।
python manage.py makemigrations
python manage.py migrate --planWas this answer clear?