我试图使用peewee来操纵一个表,该表具有包含uuid数组的列。
该模型如下:
class test_db(BaseModel):
arr = playhouse.postgres_ext.ArrayField(
peewee.UUIDField,
index_type=False
)
我想在此表中插入一个条目,并且正在使用以下代码:
arr = [uuid.UUID('d167169e-a017-4c17-8f3a-1dee98c1e563')]
x = test_db(arr=arr)
x.save()
但是我收到了
peewee.ProgrammingError: can't adapt type 'UUID'
我也尝试过这个
arr = ['d167169e-a017-4c17-8f3a-1dee98c1e563']
x = test_db(arr=arr)
x.save()
但是我收到以下错误:
peewee.ProgrammingError: column "arr" is of type uuid[] but expression is of type text[]
LINE 1: INSERT INTO "test_db" ("arr") VALUES (ARRAY['d167169e-a017-4...
^
HINT: You will need to rewrite or cast the expression.
您能为这个问题提供一些帮助吗?
非常感谢你!
这要求您注册一个UUID类型:
import psycopg2.extras
psycopg2.extras.register_uuid()
使用上面的代码,您应该能够简单地使用:
arr = ArrayField(UUIDField, index=False)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句