首页 > 解决方案 > Djongo 支持固定装置吗?

问题描述

我想创建夹具并在测试中使用它们。但是当我尝试通过运行加载它们时./manage.py loaddata test.json,我得到了DeserializationError. 追溯:

django.core.serializers.base.DeserializationError: Problem installing fixture 

'/app/test.json': Value: OrderedDict() stored in DB must be of type dict/listDid you miss 

any Migrations?: (template.template:pk=5) field_value was 'OrderedDict()'

这只是一个示例,但基本上,它会抱怨它遇到的任何 JSON 字符串。所以看起来 test.json 被反序列化了一次,并且 JSONFields 的值被保留为 JSON 字符串。所以它在这里抛出一个错误:

    # from Djongo's JSONField class 
    def to_python(self, value):
        if not isinstance(value, (dict, list)):
            raise ValueError(
                f'Value: {value} stored in DB must be of type dict/list'
                'Did you miss any Migrations?'
            )
        return value

Github上有一个类似的问题被放弃了。所以我不确定在这一点上夹具是否应该与 Djongo 一起使用。

提前感谢您的任何澄清。

标签: djangodjongo

解决方案


推荐阅读