0
0
Djangoframework~10 mins

Database migration in production 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 file for your Django app.

Django
python manage.py [1] your_app_name
Drag options to blanks, or click blank then click option'
Amakemigrations
Bmigrate
Crunserver
Dcreatesuperuser
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 command to apply migrations to the production database.

Django
python manage.py [1]
Drag options to blanks, or click blank then click option'
Amakemigrations
Bmigrate
Cshell
Dcollectstatic
Attempts:
3 left
💡 Hint
Common Mistakes
Running 'makemigrations' expecting database changes.
Using 'collectstatic' which is unrelated to database migrations.
3fill in blank
hard

Fix the error in the migration command to avoid downtime by running migrations without locking the database.

Django
python manage.py migrate --[1]
Drag options to blanks, or click blank then click option'
Aatomic
Bnoinput
Cfake
Dplan
Attempts:
3 left
💡 Hint
Common Mistakes
Using '--fake' which skips applying migrations but does not affect locking.
Using '--noinput' which only disables prompts.
4fill in blank
hard

Fill both blanks to create a migration that adds a new field with a default value without locking the table.

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

    operations = [
        migrations.AddField(
            model_name='model',
            name='new_field',
            field=models.CharField(default='default', max_length=100),
            [2]
        ),
    ]
Drag options to blanks, or click blank then click option'
A'0001_initial'
Bpreserve_default=False
Cpreserve_default=True
D'0002_auto'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong migration dependency name.
Not setting preserve_default, which causes table locking.
5fill in blank
hard

Fill all three blanks to write a safe migration that renames a column without data loss.

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

    operations = [
        migrations.RenameField(
            model_name='model',
            old_name='[2]',
            new_name='[3]',
        ),
    ]
Drag options to blanks, or click blank then click option'
A'0003_auto'
Bold_column
Cnew_column
D'0004_auto'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect migration dependency.
Mixing up old and new field names.