A migration is a way Django tracks changes to your database schema. It helps update the database structure safely as your models change.
Click to reveal answer
beginner
What command do you use to create new migrations after changing models?
You use python manage.py makemigrations to create migration files that describe the changes in your models.
Click to reveal answer
beginner
What does the python manage.py migrate command do?
It applies the migration files to the database, updating the database schema to match your current models.
Click to reveal answer
intermediate
Why should you always review migration files before applying them?
Because migrations change your database, reviewing helps avoid mistakes like deleting data or wrong schema changes.
Click to reveal answer
beginner
What is the typical workflow when you change a Django model?
1. Change your model code. 2. Run python manage.py makemigrations to create migration files. 3. Review migration files. 4. Run python manage.py migrate to update the database. 5. Test your app to ensure it works.
Click to reveal answer
Which command creates migration files after model changes?
Apython manage.py makemigrations
Bpython manage.py migrate
Cpython manage.py runserver
Dpython manage.py collectstatic
✗ Incorrect
The makemigrations command creates migration files describing model changes.
What does the migrate command do?
ACreates new migration files
BUpdates the database schema based on migration files
CStarts the Django development server
DDeletes old migration files
✗ Incorrect
The migrate command applies migrations to update the database schema.
Why is it important to review migration files before applying them?
ATo automatically fix errors in models
BTo speed up the migration process
CTo avoid accidental data loss or wrong schema changes
DTo generate documentation
✗ Incorrect
Reviewing helps catch mistakes that could harm your database.
What happens if you change a model but forget to run makemigrations?
AThe migration files will be deleted
BThe server will crash immediately
CDjango will auto-update the database
DThe database won't update to match the model changes
✗ Incorrect
Without migration files, the database stays the same and can cause errors.
Which file type stores the instructions for database changes in Django migrations?
APython files (.py)
BJSON files (.json)
CSQL files (.sql)
DText files (.txt)
✗ Incorrect
Migration files are Python scripts that describe database changes.
Explain the step-by-step workflow of making and applying migrations in Django.
Think about what happens after you change your models.
You got /5 concepts.
Why are migrations important in Django projects? Describe their role and benefits.
Consider how migrations help manage database changes over time.
You got /5 concepts.
Practice
(1/5)
1. What is the main purpose of Django migrations?
easy
A. To keep the database schema synchronized with Django models
B. To create HTML templates automatically
C. To manage user authentication
D. To optimize Django views for speed
Solution
Step 1: Understand what migrations do
Django migrations track changes in models and update the database schema accordingly.
Step 2: Compare options with this purpose
Only To keep the database schema synchronized with Django models describes keeping the database schema in sync with models, which is the core purpose of migrations.
Final Answer:
To keep the database schema synchronized with Django models -> Option A
Quick Check:
Migrations purpose = sync DB schema [OK]
Hint: Migrations sync models and database structure [OK]
Common Mistakes:
Confusing migrations with template or view management
Thinking migrations handle user authentication
Assuming migrations optimize performance
2. Which command do you run to create new migration files after changing models?
easy
A. python manage.py migrate
B. python manage.py makemigrations
C. python manage.py runserver
D. python manage.py collectstatic
Solution
Step 1: Identify the command for creating migration files
The command makemigrations generates migration files based on model changes.
Step 2: Differentiate from other commands
migrate applies migrations, runserver starts the server, and collectstatic collects static files.
Final Answer:
python manage.py makemigrations -> Option B
Quick Check:
Create migrations = makemigrations [OK]
Hint: Use makemigrations to create migration files [OK]
Common Mistakes:
Using migrate instead of makemigrations to create files
Hint: Always run makemigrations before migrate [OK]
Common Mistakes:
Thinking migrate creates migration files
Assuming server must run before migrate
Believing database must be deleted before migrating
5. You added a new field to a model and want to share the changes with your team. What is the correct workflow to update the database and share the changes safely?
hard
A. Delete the database, then run makemigrations and migrate on each machine
B. Run migrate first, then create migration files manually and share them
C. Only update the models.py file and ask team members to restart their servers
D. Run makemigrations, commit migration files to version control, then run migrate on all machines
Solution
Step 1: Create migration files after model changes
Run makemigrations to generate migration files reflecting the new field.
Step 2: Share migration files and apply them
Commit migration files to version control so the team can get them, then run migrate on each machine to update the database schema safely.
Final Answer:
Run makemigrations, commit migration files to version control, then run migrate on all machines -> Option D
Quick Check:
makemigrations + commit + migrate = safe team update [OK]
Hint: Commit migration files before migrating on other machines [OK]
Common Mistakes:
Running migrate before creating migration files
Deleting databases unnecessarily
Only updating models.py without migrations
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.