如何指定 peewee TextField 索引键长度
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)
但是这似乎不起作用,因为它 returns 这个:
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 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)
但是这似乎不起作用,因为它 returns 这个:
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()。