Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何指定peewee文本字段索引键长度_Python_Python 3.x_Orm_Mysql Python_Peewee - Fatal编程技术网

Python 如何指定peewee文本字段索引键长度

Python 如何指定peewee文本字段索引键长度,python,python-3.x,orm,mysql-python,peewee,Python,Python 3.x,Orm,Mysql Python,Peewee,如何使用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) 但是,这似乎不起作

如何使用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()。

谢谢并感谢peewee:),也许我可以根据其中的所有数据计算索引的键长度,然后再创建键长度索引