简体   繁体   English

如何指定peewee TextField索引键的长度

[英]how to specify peewee TextField index key length

How can i set the key length for TextField with peewee python orm. 如何使用peewee python orm设置TextField的键长。 I am on python3.7 and i get this error message: 我在python3.7上并且收到此错误消息:

peewee.InternalError: (1170, "BLOB/TEXT column 'text' used in key specification without a key length")

I tried specifying it like this: 我尝试像这样指定它:

text = TextField(unique = True, key_length = 255, index = True)

However that does not seem to work since it returns this: 但是,这似乎不起作用,因为它返回以下内容:

TypeError: __init__() got an unexpected keyword argument 'key_length'

Try adding the index explicitly: 尝试显式添加索引:

class Note(Model):
    content = TextField()
    class Meta:
        indexes = (
            SQL('create index note_content on note (content(100))'),
        )

Please note that specifying indexes on text fields in mysql is probably a bad idea. 请注意,在mysql中的文本字段上指定索引可能不是一个好主意。 If you know the length ahead-of-time, probably better off just using a CharField() in that case. 如果您提前知道长度,那么在这种情况下最好使用CharField()更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM