0
0
Flaskframework~5 mins

Flask-SQLAlchemy setup - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is Flask-SQLAlchemy?
Flask-SQLAlchemy is an extension for Flask that adds support for SQLAlchemy, a tool to work with databases easily using Python code instead of raw SQL.
Click to reveal answer
beginner
How do you initialize Flask-SQLAlchemy in a Flask app?
You first create a Flask app, then create a SQLAlchemy object passing the app or later call init_app(app) on it. Example: <br> app = Flask(__name__)<br>app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///mydb.sqlite3'<br>db = SQLAlchemy(app)
Click to reveal answer
beginner
What configuration key sets the database URL in Flask-SQLAlchemy?
The key is SQLALCHEMY_DATABASE_URI. It tells Flask-SQLAlchemy where your database is and what type it is, like SQLite or PostgreSQL.
Click to reveal answer
beginner
Why do you call db.create_all() in Flask-SQLAlchemy?
Calling db.create_all() creates all the tables in the database based on your model classes. It sets up the database structure you defined.
Click to reveal answer
beginner
What is a model in Flask-SQLAlchemy?
A model is a Python class that represents a table in the database. Each attribute in the class is a column in the table.
Click to reveal answer
Which configuration key sets the database location in Flask-SQLAlchemy?
ASQLALCHEMY_DATABASE_URI
BDATABASE_URL
CSQLALCHEMY_URI
DDATABASE_PATH
What does db.create_all() do in Flask-SQLAlchemy?
ADeletes all tables
BConnects to the database
CCreates tables based on models
DRuns a query
How do you link SQLAlchemy to your Flask app?
Adb = SQLAlchemy.init_app(app)
Bdb = SQLAlchemy() only
Capp = Flask() only
Ddb = SQLAlchemy(app)
What is a model in Flask-SQLAlchemy?
AA Python class representing a database table
BA database connection
CA SQL query
DA Flask route
Which database type can you use with Flask-SQLAlchemy?
AOnly SQLite
BMultiple types like SQLite, MySQL, PostgreSQL
COnly MySQL
DOnly PostgreSQL
Explain how to set up Flask-SQLAlchemy in a new Flask project.
Think about the steps from app creation to database tables.
You got /5 concepts.
    Describe what a model is in Flask-SQLAlchemy and why it is important.
    Models connect Python code to database tables.
    You got /4 concepts.