Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize Flask-Migrate with your Flask app and SQLAlchemy database.
Flask
from flask_migrate import [1] migrate = [1](app, db)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect class names like Migration or FlaskMigrate.
Forgetting to pass both app and db to Migrate.
✗ Incorrect
The Flask-Migrate extension is initialized using the Migrate class, which takes the Flask app and the SQLAlchemy database instance.
2fill in blank
mediumComplete the command to create a new migration script using Flask-Migrate.
Flask
flask db [1] -m "Initial migration"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'upgrade' instead of 'migrate' to create migration scripts.
Using 'init' which initializes the migration folder only once.
✗ Incorrect
The 'flask db migrate' command generates a new migration script based on the changes detected in the models.
3fill in blank
hardFix the error in the command to apply migrations to the database.
Flask
flask db [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'migrate' which only creates migration scripts.
Using 'downgrade' which reverts migrations.
✗ Incorrect
The 'flask db upgrade' command applies the migration scripts to update the database schema.
4fill in blank
hardFill both blanks to import and initialize the Flask app and database for migration.
Flask
from [1] import create_app from [2] import db
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing db from flask or migrations modules.
Importing create_app from incorrect modules.
✗ Incorrect
The create_app function is usually in the app module, and the database instance is imported from the models module.
5fill in blank
hardFill both blanks to write a command that downgrades the database by one migration step.
Flask
flask db [1] [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'upgrade' instead of 'downgrade'.
Omitting the step count.
✗ Incorrect
The command 'flask db downgrade -1' rolls back the database by one migration step.