flask SQLAlchemy--column 列的类型

最经常使用的SQLAlchemy列类型优化

类型名 Python类型 说 明
Integer int 普通整数,通常是 32 位
SmallInteger int 取值范围小的整数,通常是 16 位
BigInteger int 或 long 不限制精度的整数
Float float 浮点数
Numeric decimal.Decimal 定点数
String str 变长字符串
Text str 变长字符串,对较长或不限长度的字符串作了优化
Unicode unicode 变长 Unicode 字符串
UnicodeText unicode 变长 Unicode 字符串,对较长或不限长度的字符串作了优化
Boolean bool 布尔值
Date datetime.date 日期
Time datetime.time 时间
DateTime datetime.datetime 日期和时间
Interval datetime.timedelta 时间间隔
Enum str 一组字符串
PickleType 任何 Python 对象 自动使用 Pickle 序列化
LargeBinary str 二进制文件

最常使用的SQLAlchemy列选项code

选项名 说 明
primary_key 若是设为 True ,这列就是表的主键
unique 若是设为 True ,这列不容许出现重复的值
index 若是设为 True ,为这列建立索引,提高查询效率
nullable 若是设为 True ,这列容许使用空值;若是设为 False ,这列不容许使用空值
default 为这列定义默认值
相关文章
相关标签/搜索