makemigrations नामक Command
In this page:
python manage.py makemigrations
python manage.py makemigrations app_name
makemigrations चलाना
अपने project के root folder से (जहां manage.py रहता है), makemigrations चलाना आपके current models.py को last recorded migration से compare करता है और जो भी changed हो उसके लिए एक नई file लिखता है।
उदाहरण: Running makemigrations
Django scans all installed apps and prints something like 'Migrations for blog: 0002_article_published.py' for each change it found.
python manage.py makemigrations
⚠️ Run this in your own terminal or Node.js environment.
एक Single App को Target करना
makemigrations के बाद एक app का नाम pass करना scan को सिर्फ उस app तक restrict करता है, जो कई apps वाले एक बड़े project में उपयोगी है।
उदाहरण: Targeting a Single App
Only the blog app's models are checked; other installed apps are left untouched even if they also changed.
python manage.py makemigrations blog
⚠️ Run this in your own terminal or Node.js environment.
Output पढ़ना
makemigrations app का नाम और जो नई migration filename इसने बनाई वह print करता है, साथ ही हर operation क्या करता है इसकी एक छोटी list, ताकि change apply करने से पहले आप इसे sanity-check कर सकें।
उदाहरण: Reading the Output
The comment lines show Django's own explanation of the change it detected, matching the new BooleanField added to the model.
python manage.py makemigrations
# Migrations for 'blog':
# blog/migrations/0002_article_published.py
# - Add field published to article
⚠️ Run this in your own terminal or Node.js environment.
एक Migration को Name देना
--name flag आपको Django के auto-generated नाम के बजाय migration को एक meaningful नाम देने देता है, जो बाद में migrations folder को पढ़ना आसान बनाता है।
उदाहरण: Naming a Migration
The resulting file is named 0002_add_published_flag.py instead of an auto-generated description.
python manage.py makemigrations blog --name add_published_flag
⚠️ Run this in your own terminal or Node.js environment.
- makemigrations चलाना लेकिन बाद में migrate चलाना भूल जाना, इसलिए database को असल में change कभी मिलता ही नहीं।
- एक model field का नाम directly edit करना और यह मान लेना कि Django silently इसे एक rename के रूप में detect कर लेगा, बजाय यह पूछने के कि यह rename है या नई field।
- एक app के लिए makemigrations चलाना और यह उम्मीद करना कि यह unrelated apps में भी changes पकड़ ले जिन्हें touch नहीं किया गया।
- makemigrations INSTALLED_APPS में हर app को model changes के लिए scan करता है।
- यह उस app के migrations/ folder में एक नई numbered file लिखता है।
- यह खुद database को touch नहीं करता — वह migrate का काम है।
- आप नाम से एक single app को target कर सकते हैं ताकि सिर्फ वही app check हो।
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: