0
0
Djangoframework~10 mins

Migrations concept and workflow in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a new migration for your Django app.

Django
python manage.py [1]
Drag options to blanks, or click blank then click option'
Arunserver
Bmakemigrations
Ccreatesuperuser
Dmigrate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'migrate' instead of 'makemigrations' to create migration files.
Running 'runserver' expecting migrations to be created.
2fill in blank
medium

Complete the code to apply all pending migrations to the database.

Django
python manage.py [1]
Drag options to blanks, or click blank then click option'
Amigrate
Bshell
Cflush
Dmakemigrations
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'makemigrations' to apply migrations instead of creating them.
Using 'flush' which deletes data instead of applying migrations.
3fill in blank
hard

Fix the error in the migration command to specify the app name.

Django
python manage.py makemigrations [1]
Drag options to blanks, or click blank then click option'
Amyapp
Bmigrate
Call
Drunserver
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'all' or 'migrate' as app names.
Omitting the app name when you want to target a specific app.
4fill in blank
hard

Fill both blanks to create a migration that adds a new field to a model.

Django
class Migration(migrations.Migration):
    dependencies = [
        ('[1]', '0001_initial'),
    ]

    operations = [
        migrations.AddField(
            model_name='[2]',
            name='new_field',
            field=models.CharField(max_length=100),
        ),
    ]
Drag options to blanks, or click blank then click option'
Ablog
Bpost
Cuser
Dcomment
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up app name and model name.
Using capitalized model names in model_name.
5fill in blank
hard

Fill all three blanks to write a migration that removes a field from a model.

Django
class Migration(migrations.Migration):
    dependencies = [
        ('[1]', '0002_auto_20240101_1234'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='[2]',
            name='[3]',
        ),
    ]
Drag options to blanks, or click blank then click option'
Ashop
Bproduct
Cdescription
Dprice
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong migration dependency name.
Confusing field name with model name.