0
0
Flaskframework~10 mins

Column types and constraints in Flask - Interactive Code Practice

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

Complete the code to define a string column named 'username' in a Flask SQLAlchemy model.

Flask
username = db.Column(db.[1](50), nullable=False)
Drag options to blanks, or click blank then click option'
AInteger
BString
CBoolean
DFloat
Attempts:
3 left
💡 Hint
Common Mistakes
Using Integer or Boolean instead of String for text data.
Forgetting to specify max length for String.
2fill in blank
medium

Complete the code to add a primary key constraint to the 'id' column.

Flask
id = db.Column(db.Integer, [1]=True)
Drag options to blanks, or click blank then click option'
Aunique
Bnullable
Cprimary_key
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'unique=True' instead of 'primary_key=True'.
Forgetting to set primary_key on the id column.
3fill in blank
hard

Fix the error in the code to make the 'email' column unique and not nullable.

Flask
email = db.Column(db.String(120), unique=[1], nullable=[2])
Drag options to blanks, or click blank then click option'
ATrue
BFalse
CNone
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting nullable=True which allows empty emails.
Not setting unique=True to prevent duplicates.
4fill in blank
hard

Fill both blanks to define a column 'age' that stores integers and cannot be null.

Flask
age = db.Column(db.[1], [2]=False)
Drag options to blanks, or click blank then click option'
AInteger
BString
Cnullable
Dprimary_key
Attempts:
3 left
💡 Hint
Common Mistakes
Using String type for age.
Forgetting to set nullable=False.
5fill in blank
hard

Fill all three blanks to define a 'created_at' column with DateTime type, defaulting to current time, and not nullable.

Flask
created_at = db.Column(db.[1], default=[2], [3]=False)
Drag options to blanks, or click blank then click option'
ADateTime
Bfunc.now()
Cnullable
DString
Attempts:
3 left
💡 Hint
Common Mistakes
Using String instead of DateTime.
Not setting default to current time.
Allowing nullable=True which can cause missing timestamps.