0
0
Flaskframework~20 mins

Database migrations with Flask-Migrate - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Flask-Migrate Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:00remaining
What is the primary purpose of Flask-Migrate?
Flask-Migrate is a tool used in Flask applications. What does it mainly help developers do?
AAutomatically generate HTML forms for database models
BManage database schema changes over time using migrations
CHandle user authentication and authorization
DServe static files like images and CSS
Attempts:
2 left
💡 Hint
Think about how your database structure changes as your app grows.
component_behavior
intermediate
1:30remaining
What happens when you run 'flask db migrate'?
In a Flask app using Flask-Migrate, what does the command 'flask db migrate' do?
ACreates a new migration script by comparing models to the current database schema
BApplies all pending migrations to the database
CDeletes all migration scripts
DRolls back the last applied migration
Attempts:
2 left
💡 Hint
This command prepares changes but does not apply them yet.
📝 Syntax
advanced
2:00remaining
Identify the correct way to initialize Flask-Migrate
Given a Flask app and SQLAlchemy db instance, which code correctly initializes Flask-Migrate?
Flask
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate

app = Flask(__name__)
db = SQLAlchemy(app)

# Which line correctly initializes Migrate?
Amigrate = Migrate(app, db)
Bmigrate = Migrate(db, app)
Cmigrate = Migrate(app)
Dmigrate = Migrate(db)
Attempts:
2 left
💡 Hint
Check the order of arguments in the Migrate constructor.
state_output
advanced
1:30remaining
What is the state of the database after 'flask db upgrade'?
After running 'flask db upgrade' in a Flask app using Flask-Migrate, what is true about the database?
AThe database schema is rolled back to the previous migration
BThe database schema is reset to the initial empty state
CNo changes are applied to the database schema
DThe database schema matches the latest migration scripts
Attempts:
2 left
💡 Hint
This command applies all migrations that have not been applied yet.
🔧 Debug
expert
2:30remaining
Why does 'flask db migrate' fail with 'Target database is not up to date'?
You run 'flask db migrate' but get an error: 'Target database is not up to date'. What is the most likely cause?
AThe Flask app is missing the SQLAlchemy db instance
BThe migration folder is missing
CThere are unapplied migrations; you must run 'flask db upgrade' first
DThe database URI is incorrect in the Flask config
Attempts:
2 left
💡 Hint
Think about the order of applying migrations before creating new ones.