Data for Flasks
Data in Flask means storing and querying application records, most often with a relational database through SQLAlchemy and the Flask-SQLAlchemy extension, or with raw sqlite3. It covers defining models, creating tables, running queries inside request handlers and managing schema changes with migrations such as Flask-Migrate and Alembic.
Stage: Building an App · Part of the Flask roadmap · Last reviewed 19 November 2026
What to learn in Data
- Define a model class and map it to a database table
- Insert, query, update and delete rows within a request
- Manage the database session and commit or roll back correctly
- Model one-to-many relationships between tables
- Generate and apply schema migrations with Flask-Migrate
Data interview questions
Why should you use migrations instead of calling create_all every time?
create_all only creates missing tables and never alters existing ones, so a changed column is silently ignored. Migrations record each schema change as a versioned script that can be applied or reversed, keeping development, staging and production databases consistent as the models evolve.
How do you avoid SQL injection in a Flask app?
Never build SQL strings by joining user input. Use the SQLAlchemy ORM or parameterised queries so the database driver sends values separately from the statement. With raw sqlite3, pass a tuple of parameters with question mark placeholders rather than formatting the query string.
Where Data fits in the Flask roadmap
Data belongs to the Building an App stage (beginner level). Follow the tutorial.
Other units in this stage
Back to the full Flask roadmap