我正在尝试从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()),
当你说你的MongoDB一切正常时,你想说什么??数据库已填充或正常,因为您在该端未看到任何错误,请指定。。你记得把你的头发加上去吗设置.py你知道吗
相关问题 更多 >
编程相关推荐