Django + PostgreSQL:JSONField的数据库表示正在发生变化

时间:2021-05-09 22:57:14
  • PostgreSQL 9.4.12
  • Django 1.10.7

With this minimal class :

有了这个最小的课程:

from django.contrib.postgres.fields import JSONField

class Foobar(models.Model):
    extra_data = JSONField(blank=True, default="")

I run manage.py shell_plus :

我运行manage.py shell_plus:

In [2]: a=Foobar.objects.create()

In [3]: a.extra_data={}

In [4]: a.save()

In [6]: a.extra_data
Out[6]: {}

In [7]: a.refresh_from_db()

In [8]: a.extra_data
Out[8]: '{}'

In [9]: a.save()

In [10]: a.refresh_from_db()

In [11]: a.extra_data
Out[11]: '"{}"'

What could be the reason the JSONField value is quoted at each database save?

在每个数据库保存时引用JSONField值的原因是什么?

1 个解决方案

#1


0  

Found it. This is a known incompatibility between django-jsonfield and django.contrib.postgres.fields.JSONField that cannot be used in same project.
cf https://bitbucket.org/schinckel/django-jsonfield/issues/57/cannot-use-in-the-same-project-as-djangos

找到了。这是django-jsonfield和django.contrib.postgres.fields.JSONField之间已知的不兼容性,不能在同一个项目中使用。 cf https://bitbucket.org/schinckel/django-jsonfield/issues/57/cannot-use-in-the-same-project-as-djangos

#1


0  

Found it. This is a known incompatibility between django-jsonfield and django.contrib.postgres.fields.JSONField that cannot be used in same project.
cf https://bitbucket.org/schinckel/django-jsonfield/issues/57/cannot-use-in-the-same-project-as-djangos

找到了。这是django-jsonfield和django.contrib.postgres.fields.JSONField之间已知的不兼容性,不能在同一个项目中使用。 cf https://bitbucket.org/schinckel/django-jsonfield/issues/57/cannot-use-in-the-same-project-as-djangos