Challenge - 5 Problems
Migration Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens after running
python manage.py migrate?You have created a new model in your Django app and run
python manage.py makemigrations. What is the immediate effect of running python manage.py migrate?Attempts:
2 left
💡 Hint
Think about what changes the database structure.
✗ Incorrect
Running
migrate applies the migration files to the database, updating its schema to match your models.📝 Syntax
intermediate1:30remaining
Identify the correct migration command to create migration files
Which command correctly creates migration files after you change your Django models?
Attempts:
2 left
💡 Hint
This command prepares the changes but does not apply them yet.
✗ Incorrect
makemigrations creates migration files based on model changes.🔧 Debug
advanced2:30remaining
Why does this migration fail with an error?
You added a new non-nullable field without a default to an existing model and ran
makemigrations. The migration fails when applying. Why?Django
class Book(models.Model): title = models.CharField(max_length=100) published_date = models.DateField() author = models.CharField(max_length=100, null=False) # New field added without default
Attempts:
2 left
💡 Hint
Think about what happens to existing data when adding a required field.
✗ Incorrect
Adding a non-nullable field without a default causes the database to fail because existing rows have no value for that field.
🧠 Conceptual
advanced2:00remaining
What is the role of the
Migration class in Django migration files?Each migration file contains a
Migration class. What does this class define?Attempts:
2 left
💡 Hint
Think about what migrations do to the database.
✗ Incorrect
The
Migration class lists operations like creating or altering tables to apply or undo schema changes.❓ state_output
expert3:00remaining
What is the state of the database after running these commands in order?
You run these commands in your Django project:
1.
2.
3. You modify a model by renaming a field
4.
5.
What is true about the database after step 5?
1.
python manage.py makemigrations2.
python manage.py migrate3. You modify a model by renaming a field
4.
python manage.py makemigrations5.
python manage.py migrateWhat is true about the database after step 5?
Attempts:
2 left
💡 Hint
Consider what migrations do when you rename a field and apply migrations.
✗ Incorrect
Django generates a migration to rename the field and applies it, so the database schema updates accordingly.