[英]how to specify peewee TextField index key length
如何使用peewee python orm设置TextField的键长。 我在python3.7上并且收到此错误消息:
peewee.InternalError: (1170, "BLOB/TEXT column 'text' used in key specification without a key length")
我尝试像这样指定它:
text = TextField(unique = True, key_length = 255, index = True)
但是,这似乎不起作用,因为它返回以下内容:
TypeError: __init__() got an unexpected keyword argument 'key_length'
尝试显式添加索引:
class Note(Model):
content = TextField()
class Meta:
indexes = (
SQL('create index note_content on note (content(100))'),
)
请注意,在mysql中的文本字段上指定索引可能不是一个好主意。 如果您提前知道长度,那么在这种情况下最好使用CharField()更好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.