0
0
Flaskframework~10 mins

Flask-SQLAlchemy setup - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the SQLAlchemy class from flask_sqlalchemy.

Flask
from flask_sqlalchemy import [1]
Drag options to blanks, or click blank then click option'
Acreate_app
BFlask
CSQLAlchemy
Ddb
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Flask instead of SQLAlchemy.
Using 'db' which is usually the instance name, not the class.
Trying to import create_app which is unrelated here.
2fill in blank
medium

Complete the code to create a Flask app instance.

Flask
app = [1](__name__)
Drag options to blanks, or click blank then click option'
AFlask
BSQLAlchemy
Ccreate_app
Dapp
Attempts:
3 left
💡 Hint
Common Mistakes
Using SQLAlchemy instead of Flask to create the app.
Calling create_app which is a pattern but not the class itself.
Assigning app to itself.
3fill in blank
hard

Fix the error in the code to initialize the SQLAlchemy object with the Flask app.

Flask
db = SQLAlchemy([1])
Drag options to blanks, or click blank then click option'
Aapp
BSQLAlchemy
CFlask
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the class SQLAlchemy instead of the app instance.
Passing Flask class instead of the app instance.
Passing None which causes errors.
4fill in blank
hard

Fill both blanks to configure the database URI and enable track modifications.

Flask
app.config['SQLALCHEMY_DATABASE_URI'] = [1]
app.config[[2]] = False
Drag options to blanks, or click blank then click option'
A'sqlite:///test.db'
B'SQLALCHEMY_TRACK_MODIFICATIONS'
C'SQLALCHEMY_ECHO'
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using True instead of False for track modifications.
Using wrong config keys like 'SQLALCHEMY_ECHO'.
Wrong URI format.
5fill in blank
hard

Fill all three blanks to define a simple User model with id, username, and email fields.

Flask
class User(db.Model):
    id = db.Column(db.Integer, primary_key=[1])
    username = db.Column(db.String(80), unique=[2], nullable=False)
    email = db.Column(db.String(120), unique=[3], nullable=False)
Drag options to blanks, or click blank then click option'
ATrue
BFalse
CNone
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting primary_key to False or None.
Not setting unique to True for username or email.
Using 0 instead of True or False.