【问题标题】:HStore field insert issueHStore 字段插入问题
【发布时间】:2015-08-02 13:51:46
【问题描述】:

我正在尝试从我的 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。迁移也很成功。我不明白为什么它总是失败。

【问题讨论】:

  • 如果避免使用 get_or_create 而是使用模型保存方法会发生什么?

标签: django django-queryset django-hstore


【解决方案1】:

Django 的 HStoreField 只接受字符串值,因此出现错误:function hstore(text[], integer[]) does not exist

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

【讨论】:

  • 在 Django 上 HStoreField docsA field for storing mappings of strings to strings.
猜你喜欢
  • 2014-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-16
  • 2016-01-06
相关资源
最近更新 更多