Flask-SQLAlchemy的模型创建参数解析
一个简单的例子
|
|
db.Column 说明
-
源码
site-packages/sqlalchemy/sql/schema.py -
方法
Column(SchemaItem, ColumnClause) -
ColumnClause说明
| 参数 | 类型 | 默认 | 修改默认 | 备注 |
|---|---|---|---|---|
| tablename | str | 类名派生 | __tablename__ = 'users' |
表名 |
| primary_key | bool | False | primary_key=True |
主键 |
| nullable | bool | primary_key 取反 | nullable=True |
是否为空 |
| default | None | default=xxx |
默认值 | |
| index | bool | None | index=True |
索引 |
| unique | bool | None | unique=True |
唯一 |
表名是自动地为您设置好的,除非您想要覆盖它。 它是从转成小写的类名派生出来的, 即 “CamelCase” 转换为 “camel_case”
SchemaItem db类型说明
-
源码
site-packages/sqlalchemy/sql/sqltypes.py -
多种SQL类型
-
Indexable -
String -
Text -
Unicode -
UnicodeText -
Integer -
SmallInteger -
BigInteger -
Numeric -
Float -
DateTime -
Date -
Time -
LargeBinary -
Binary -
Enum -
Boolean
-