Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django将数据插入到ManyToManyfield AssertionError错误_Python_Django - Fatal编程技术网

Python Django将数据插入到ManyToManyfield AssertionError错误

Python Django将数据插入到ManyToManyfield AssertionError错误,python,django,Python,Django,模型 看法 序列化程序 类注册序列化程序(DynamicFieldsMixin、DynamicFieldsModelSerializer): dependents=DependentSerializer(many=True,required=False) 错误: class Meta: model = models.Enrollee fields = '__all__' 在这里,我试图为我的家属发送嵌套数据(ManyToManyField) 但是,在插入数据时出现上述错误 我们

模型

看法

序列化程序

类注册序列化程序(DynamicFieldsMixin、DynamicFieldsModelSerializer): dependents=DependentSerializer(many=True,required=False)

错误:

class Meta:
    model = models.Enrollee
    fields = '__all__'
在这里,我试图为我的家属发送嵌套数据(ManyToManyField) 但是,在插入数据时出现上述错误

我们有没有办法做到这一点

    _nested_writes
        assert not any(
    AssertionError: The `.create()` method does not support writable nested fields by default.
    Write an explicit `.create()` method for serializer `api.serializers.EnrolleeSerializer`, or set `read_only=True` on nested serializer fields.
以上是我使用post方法发送的数据

请看一看

使用
class Meta:
    model = models.Enrollee
    fields = '__all__'
    _nested_writes
        assert not any(
    AssertionError: The `.create()` method does not support writable nested fields by default.
    Write an explicit `.create()` method for serializer `api.serializers.EnrolleeSerializer`, or set `read_only=True` on nested serializer fields.
{
  "first_name":"soubhagya",
  "dependents" : [
   {
     "first_name":"soubhagya"
   }
  ]
}