django - HStore字段插入问题

标签 django django-queryset django-hstore

我试图从 python shell 中将字典插入到 htore 中,但不断收到此错误:

django.db.utils.ProgrammingError: function hstore(text[], integer[]) does not exist
LINE 1: ...ula" = hstore(ARRAY['function', 'formula'], ARRAY[hstore(ARR...
                                                         ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

我使用的查询集是这样的:

Formula.objects.get_or_create(formula={ 'function': { 'round': 0}, 'formula': {'a':  0.2 , 'b': 5, 'c': 4, 'd': 4, 'e': 1}})

此外,我还创建了 hstore 扩展并添加了应用程序 django_hstore。迁移也成功了。我不明白为什么它总是失败。

最佳答案

Django 的 HStoreField 仅接受字符串值,因此出现错误:function hstore(text[], integer[]) 不存在

尝试在示例中使用 { 'round': '0'} 而不是 { 'round': 0}

关于django - HStore字段插入问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30364529/

相关文章:

python - Django预取相关和选择相关

python - Django:更新查询集中对象的顺序属性

django - 使用Tag模型创建ManytoMany关系

migrate - django.db.utils.ProgrammingError : can't adapt type 'dict' after I tried to add a Hstorefield to my model

python - 使用模板标签在html模板中求和

Django - ORM 问题

django - 如何使用Django REST框架实现管理员登录和注销?

django - Django查询在哪里

django-hstore DictionaryField 返回字符串而不是字典

python - django-hstore 与 Django 1.6 的兼容性问题