Reputation: 1257
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()),
Upvotes: 0
Views: 414
Reputation: 386
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 = (
''
)
Upvotes: 1