Flask database framework extension Flask-SQLAlchemy

First, install the extension

pip install flask-sqlalchemy
pip install flask-mysqldb

二、SQLAlchemy

SQLAlchemy common field type

Type Name Type in python Explanation
Integer int Plain integers, typically 32
SmallInteger int A small range of integers, typically 16
BigInteger int or long Does not limit the integer precision
Float float Float
Numeric decimal.Decimal Plain integers, typically 32
String str Variable-length strings
Text str Variable-length string, the string is not limited to or longer length optimized
Unicode unicode Variable-length Unicode string
UnicodeText unicode Variable-length Unicode strings, strings of length longer or not optimized
Boolean bool Boolean value
Date datetime.date time
Time datetime.datetime Date and Time
LargeBinary str binary file

Commonly used SQLAlchemy Column Options

Option name Explanation
primary_key If the primary key True, the representative of the table
unique If True, the representative of this column does not allow duplicate values
index If you create an index for this column to True, improve query efficiency
nullable If True, it allows nulls, If False, does not allow nulls
default The default value for this column definition

Commonly used SQLAlchemy relationship options

Option name Explanation
backref Adding another model referenced in the reverse relations
primary join Explicitly specify the conditions of use of the coupling between the two models
uselist If False, do not use the list, and use a scalar value
order_by Specify the relationship recorded in Sort
secondary Specified ordering many-recorded
secondary join When not in SQLAlchemy discretion, specify two join condition in many relationship

Guess you like

Origin www.cnblogs.com/yang-2018/p/11025764.html