Django Rest Fram中id处的迁移错误

2024-09-29 21:59:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从MongoDB数据库创建api端点。一切似乎都很正常,但我不断得到以下错误:

MigrationError at /mymodel/
id

我不知道这是从哪里来的,因为这是所有的错误页说。你知道吗

这是我的模型:

class mymodel(models.Model):
    firstfield = models.FloatField()
    secondfield = models.FloatField()
    thirdfield = models.CharField(max_length=15)

    def save(self, *args, using=None, **kwargs):
        super(mymodel, self).save(*args, using='mydb', **kwargs)

序列化程序:

class mymodelSerializer(serializers.ModelSerializer):

    class Meta:
        model = mymodel
        fields = ('firstfield', 'secondfield', 'thirdfield')

    def create(self, validated_data):
        return mymodel.create(**validated_data)

我的观点:

class mymodelList(generics.ListCreateAPIView):
    queryset = mymodel.objects.using('mydb').all()
    serializer_class = mymodelSerializer


class mymodelDetail(generics.RetrieveUpdateDestroyAPIView):
    queryset = mymodel.objects.using('mydb').all()
    serializer_class = mymodelSerializer

和我的URL:

path('mymodel/', views.mymodelList.as_view()),
path('mymodel/<int:pk>/', views.mymodelDetail.as_view()),

Tags: selfmodelssavedef错误argsclassmymodel
1条回答
网友
1楼 · 发布于 2024-09-29 21:59:39

当你说你的MongoDB一切正常时,你想说什么??数据库已填充或正常,因为您在该端未看到任何错误,请指定。。你记得把你的头发加上去吗设置.py你知道吗

CORS_ORIGIN_ALLOW_ALL = True
# what abou whitelist because that's where you db will be served ip/fqdn and port 
CORS_ORIGIN_WHITELIST = (
  ''
) 

相关问题 更多 >

    热门问题