1

我切换到 django 2,因为它支持使用 inspectdb 检测 json 字段,但是当我运行 inspectdb 时,它会生成 django.contrib.postgresql.fields.JSONField 我不知道从哪里导入它。

如此处 django 文档中所述 django_inpectdb_doc

我知道可以通过添加 import django.contrib.postgres.fields.JSONField 来修复它,但问题是它是自动生成的 django.contrib.postgre sql .fields.JSONField (注意粗体文本)。

class AsyncResultsStore(models.Model):
    task_id = models.CharField(max_length=255)
    created = models.DateTimeField(blank=True, null=True)
    status = models.CharField(max_length=255)
    result = django.contrib.postgresql.fields.JSONField(blank=True, null=True)
    info = models.CharField(max_length=255)
    arguments = django.contrib.postgresql.fields.JSONField(blank=True, null=True)
    chip_meas_result = models.ForeignKey(Chipmeasurementresult, models.DO_NOTHING, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'async_results_store'

我想要做:

import django.contrib.postgres.fields

但这是不可能的,因为生成的行是:

django.contrib.postgresql.fields

postgressql 而不是 postgres

在上面的文档链接中,指定我应该放入 settings.py 安装的应用程序:'django.contrib.postgres'

我做了。

我应该从其他地方导入还是这是 django2 中的错误行为?

如果我确实 import django.contrib 我得到的错误是:

result = django.contrib.postgresql.fields.JSONField(blank=True, null=True)
AttributeError: module 'django.contrib' has no attribute 'postgresql'
4

1 回答 1

0

这是 Django 的自省代码中的一个错误。您可以更改要使用的模型django.contrib.postgres.fields,并添加import django.contrib.postgres.fields到您的models.py.

Django ticket 29307将在Django 2.0.5中修复该问题。

于 2018-04-09T16:15:17.123 回答