Flask-SQLAlchemy常用的SQLAlchemy列選項

2021年9月24日10:41:24 發(fā)表評論 2,246 ℃

 

常用的SQLAlchemy列選項

類型名

python中類型

說明

Integer

int

普通整數(shù),一般是32位

SmallInteger

int

取值范圍小的整數(shù),一般是16位

BigInteger

int或long

不限制精度的整數(shù)

Float

float

浮點數(shù)

Numeric

decimal.Decimal

普通整數(shù),一般是32位

String

str

變長字符串

Text

str

變長字符串,對較長或不限長度的字符串做了優(yōu)化

Unicode

unicode

變長Unicode字符串

UnicodeText

unicode

變長Unicode字符串,對較長或不限長度的字符串做了優(yōu)化

Boolean

bool

布爾值

Date

datetime.date

時間

Time

datetime.datetime

日期和時間

LargeBinary

str

二進制文件

 

常用的SQLAlchemy關(guān)系選項

選項名

說明

primary_key

如果為True,代表表的主鍵

unique

如果為True,代表這列不允許出現(xiàn)重復(fù)的值

index

如果為True,為這列創(chuàng)建索引,提高查詢效率

nullable

如果為True,允許有空值,如果為False,不允許有空值

default

為這列定義默認(rèn)值

 

選項名

說明

backref

在關(guān)系的另一模型中添加反向引用

primaryjoin

明確指定兩個模型之間使用的聯(lián)結(jié)條件

uselist

如果為False,不使用列表,而使用標(biāo)量值

order_by

指定關(guān)系中記錄的排序方式

secondary

指定多對多中記錄的排序方式

secondaryjoin

在SQLAlchemy中無法自行決定時,指定多對多關(guān)系中的二級聯(lián)結(jié)條件

【騰訊云】云服務(wù)器、云數(shù)據(jù)庫、COS、CDN、短信等云產(chǎn)品特惠熱賣中

發(fā)表評論

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: