0
0
Flaskframework~10 mins

Model definition 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 import SQLAlchemy from flask_sqlalchemy.

Flask
from flask_sqlalchemy import [1]
Drag options to blanks, or click blank then click option'
AModel
BFlask
CSQLAlchemy
DBase
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'Model' directly instead of 'SQLAlchemy'.
Using 'Flask' which is unrelated to models.
Trying to import 'Base' which is not from flask_sqlalchemy.
2fill in blank
medium

Complete the code to define a model class named User inheriting from the base model.

Flask
class User([1]):
Drag options to blanks, or click blank then click option'
Adb.Model
BBase
CModel
Dobject
Attempts:
3 left
💡 Hint
Common Mistakes
Inheriting from 'object' which is a plain Python class.
Using 'Base' which is from SQLAlchemy core, not Flask-SQLAlchemy.
Using 'Model' without prefix which causes NameError.
3fill in blank
hard

Fix the error in the model field definition to create an integer primary key named id.

Flask
id = db.Column([1], primary_key=True)
Drag options to blanks, or click blank then click option'
Adb.Integer
Bdb.Float
Cdb.Boolean
Ddb.String(50)
Attempts:
3 left
💡 Hint
Common Mistakes
Using String type for primary key which is uncommon here.
Using Boolean or Float which are not suitable for primary keys.
4fill in blank
hard

Fill both blanks to define a username column that is a string of max length 80 and must be unique.

Flask
username = db.Column([1](80), [2]=True)
Drag options to blanks, or click blank then click option'
Adb.String
Bunique
Cnullable
Ddb.Integer
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'nullable' instead of 'unique' for uniqueness.
Using 'Integer' instead of 'String' for username.
5fill in blank
hard

Fill all three blanks to define an email column that is a string of max length 120, unique, and cannot be null.

Flask
email = db.Column([1](120), [2]=True, [3]=False)
Drag options to blanks, or click blank then click option'
Adb.Integer
Bunique
Cnullable
Ddb.String
Attempts:
3 left
💡 Hint
Common Mistakes
Setting nullable=True which allows empty emails.
Using Integer type for email which is incorrect.