簡體   English   中英

如何指定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)

但是,這似乎不起作用,因為它返回以下內容:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM