0
0
Flaskframework~10 mins

Creating tables (db.create_all) in Flask - Interactive Practice

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

Complete the code to import the Flask class.

Flask
from flask import [1]
Drag options to blanks, or click blank then click option'
AModel
BApp
CDatabase
DFlask
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'App' instead of 'Flask' will cause an import error.
Trying to import 'Database' or 'Model' from flask is incorrect.
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
BApp
Ccreate_app
DApplication
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Application' or 'App' will cause a NameError.
Using 'create_app' is a pattern but not the class constructor.
3fill in blank
hard

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

Flask
db = SQLAlchemy()
db.[1](app)
Drag options to blanks, or click blank then click option'
Ainitialize
Bstart
Cinit_app
Dcreate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'initialize' or 'start' causes AttributeError.
Using 'create' is not a method of SQLAlchemy instance.
4fill in blank
hard

Fill both blanks to define a simple model with an id primary key and a name column.

Flask
class User(db.Model):
    id = db.Column(db.[1], primary_key=True)
    name = db.Column(db.[2](50))
Drag options to blanks, or click blank then click option'
AInteger
BString
CText
DFloat
Attempts:
3 left
💡 Hint
Common Mistakes
Using Text for id causes errors.
Using Float for name is incorrect.
5fill in blank
hard

Fill all three blanks to create tables in the database after app context is pushed.

Flask
with app.[1]():
    db.[2]()
    print('[3] tables created!')
Drag options to blanks, or click blank then click option'
Aapp_context
Bcreate_all
CDatabase
DApp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'App' instead of 'app_context' causes errors.
Calling 'create' instead of 'create_all' misses table creation.