简体   繁体   中英

Migration error at id in Django Rest Framework

I'm trying to create an api endpoint from my MongoDB database. Everything seems normal, but i keep getting the following error:

MigrationError at /mymodel/
id

I have no idea where is this coming from, since this is everything the error page says.

Here is my model:

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)

Serializers:

class mymodelSerializer(serializers.ModelSerializer):

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

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

My views:

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

And my urls:

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

When you say everything is normal on your MongoDB what are you trying to refer?? the database is populated or normal as you don't see any error on that end please specify.. did you remember to add on your settings.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 = (
  ''
) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM