当前位置:   article > 正文

Flask SQLAlchemy数据类型_sqlalchemy mediumtext

sqlalchemy mediumtext

1 数据类型

类型名MySQL类型python类型描述
SmallIntegersmallintint取值范围较小,一般为16位
Integerintint普通整数,一般32位
BigIntegerbigintint/long不限精度的整数
Floatfloatfloat浮点数
Numericdecimaldecimal.Decimal定点数
Stringvarcharstr变长字符串
Text(65536)tinytextstr变长字符串,64K, 2 16 − 1 2^{16}-1 2161=65535bytes
Text(16777216)mediumtextstr变长字符串,max16M, 2 24 − 1 2^{24}-1 2241=16777215bytes
Text(4294967295)longtextstr变长字符串,max32M, 2 32 − 1 2^{32}-1 2321=4294967295bytes
LargeBinaryblobstr二进制文件,64K
LargeBinary(65536)mediumblobstr二进制,max16M
LargeBinary(16777216)longblobstr二进制,max32M
PickleTypeblob任何python对象自动使用Pickle序列化,只有blob
Unicodevarcharunicode变长字符串
UnicodeTexttextunicode变长字符串,64K
Booleantinyintbool布尔值
Datedatedatetime.date日期
Timetimedate.time时间
DateTimedatetimedatetime.datetime日期和时间
Intervaldatetimedatetime.timedelta时间间隔
Enumenumstr一组字符串

2 数据库类型设计

  • 建立MySQL表
class Data(db.Model):
	__tablename__ = "datas"
	id = db.Column(db.Integer, primary_key=True)
	smallInteger = db.Column(db.SmallInteger)
	bigInteger = db.Column(db.BigInteger)
	floatData = db.Column(db.Float(10))
	numericData = db.Column(db.Numeric(10))
	stringData = db.Column(db.String(250))
	textData = db.Column(db.Text(200))
	mediumText = db.Column(db.Text(65536))
	longText = db.Column(db.Text(16777216))
	largeBinary = db.Column(db.LargeBinary(300))
	mediumBlob = db.Column(db.LargeBinary(65536))
	longBlob = db.Column(db.LargeBinary(16777216))
	pickle = db.Column(db.PickleType)
	mediumPickle = db.Column(db.PickleType(65536))
	longPickle = db.Column(db.PickleType(16777216))
	unicodeData = db.Column(db.Unicode(10))
	unicodeText = db.Column(db.UnicodeText)
	booleanData = db.Column(db.Boolean(0))
	dateData = db.Column(db.Date)
	timeData = db.Column(db.Time)
	dateTime = db.Column(db.DateTime)
	interval = db.Column(db.Interval)
	enumData = db.Column(db.Enum('father', 'mother'))
	def __repr__(self):
		return "Data {}".format(self.id)
	
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • MySQL表结构
+--------------+-------------------------+------+-----+---------+----------------+
| Field        | Type                    | Null | Key | Default | Extra          |
+--------------+-------------------------+------+-----+---------+----------------+
| id           | int(11)                 | NO   | PRI | NULL    | auto_increment |
| smallInteger | smallint(6)             | YES  |     | NULL    |                |
| bigInteger   | bigint(20)              | YES  |     | NULL    |                |
| floatData     |  float                   | YES  |     | NULL    |                |
| numericData  | decimal(10,0)           | YES  |     | NULL    |                |
| stringData   | varchar(250)            | YES  |     | NULL    |                |
| textData     | tinytext                | YES  |     | NULL    |                |
| mediumText   | mediumtext              | YES  |     | NULL    |                |
| longText     | longtext                | YES  |     | NULL    |                |
| largeBinary  | blob                    | YES  |     | NULL    |                |
| mediumBlob   | mediumblob              | YES  |     | NULL    |                |
| longBlob     | longblob                | YES  |     | NULL    |                |
| pickle       | blob                    | YES  |     | NULL    |                |
| mediumPickle | blob                    | YES  |     | NULL    |                |
| longPickle   | blob                    | YES  |     | NULL    |                |
| unicodeData  | varchar(10)             | YES  |     | NULL    |                |
| unicodeText  | text                    | YES  |     | NULL    |                |
| booleanData  | tinyint(1)              | YES  |     | NULL    |                |
| dateData     | date                    | YES  |     | NULL    |                |
| timeData     | time                    | YES  |     | NULL    |                |
| dateTime     | datetime                | YES  |     | NULL    |                |
| interval     | datetime                | YES  |     | NULL    |                |
| enumData     | enum('father','mother') | YES  |     | NULL    |                |
+--------------+-------------------------+------+-----+---------+----------------+

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

3 Flask-MySQL键属性

属性描述生效值
primary_key主键True
unique键值唯一性True
index索引True
nullable空值True
default默认值null

[参考文献]

[1]https://www.cnblogs.com/Orangeorchard/p/8097547.html
[2]https://blog.csdn.net/skdkjzz/article/details/20469721


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/927238
推荐阅读
相关标签
  

闽ICP备14008679号