Challenge - 5 Problems
Column Types and Constraints Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate2:00remaining
Identify the correct SQLAlchemy column type for storing large text
Which SQLAlchemy column type is best suited for storing large text data in a Flask model?
Attempts:
2 left
💡 Hint
Think about which type can hold long paragraphs without a fixed length.
✗ Incorrect
db.Text is used for large text fields without a length limit, unlike db.String which has a max length.
❓ component_behavior
intermediate2:00remaining
Effect of nullable constraint on a Flask model column
What happens if you set
nullable=False on a column in a Flask SQLAlchemy model?Attempts:
2 left
💡 Hint
Think about whether the database allows empty or missing values in that column.
✗ Incorrect
Setting nullable=False means the database requires a value; NULL is not allowed.
❓ state_output
advanced2:00remaining
Output of unique constraint violation in Flask SQLAlchemy
Given a Flask model with a column defined as
email = db.Column(db.String(120), unique=True), what happens if you try to add two users with the same email?Flask
user1 = User(email='test@example.com') db.session.add(user1) db.session.commit() user2 = User(email='test@example.com') db.session.add(user2) db.session.commit()
Attempts:
2 left
💡 Hint
What does a unique constraint do when a duplicate value is inserted?
✗ Incorrect
The unique constraint prevents duplicate values. The database raises an IntegrityError on violation.
🔧 Debug
advanced2:00remaining
Identify the error in this Flask SQLAlchemy column definition
What is wrong with this column definition?
age = db.Column(db.Integer, nullable='False')
Flask
age = db.Column(db.Integer, nullable='False')Attempts:
2 left
💡 Hint
Check the data type expected for the nullable parameter.
✗ Incorrect
The nullable parameter expects a boolean (True or False), not a string.
🧠 Conceptual
expert3:00remaining
Understanding composite primary keys in Flask SQLAlchemy
Which of the following correctly defines a composite primary key on columns
user_id and order_id in a Flask SQLAlchemy model?Attempts:
2 left
💡 Hint
Composite primary keys can be explicitly defined using __table_args__ with PrimaryKeyConstraint.
✗ Incorrect
Defining multiple columns with primary_key=True works but is less explicit. Using __table_args__ with PrimaryKeyConstraint is the correct explicit way.