Creating Tables
The db.create_all() function locates all the subclasses of db.Model and creates corresponding tables in the database for them
Inserting Rows
The constructors for models accept initial values for the model attributes as keyword arguments. Note that the role attribute can be used, even though it is not a real database column but a high-level representation of the one-to-many relationship. The id attribute of these new objects is not set explicitly: the primary keys in many databases are managed by the database itself. The objects exist only on the Python side so far; they have not been written to the database yet.
Modifying Rows
The add() method of the database session can also be used to update models. Continuing in the same shell session, the following example renames the "Admin" role to
"Administrator":
Deleting Rows
The database session also has a delete() method. The following example deletes the "Moderator" role from the database:
Querying Rows
Flask-SQLAlchemy makes a query object available in each model class. The most basic query for a model is triggered with the all() method, which returns the entire contents of the corresponding table:
Comments