Python/DJango 'django.db.utils.OperationalError: no such table' в Django Rest Framework (DRF)
<
Internal Server Error: /polls/6/choices/19/vote/
Traceback (most recent call last):
File "D:\Studio\Python\REST\elections\env\lib\site-packages\django\db\backends\sqlite3\base.py", line 303, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: main.vote_choice__old
File "D:\Studio\Python\REST\elections\env\lib\site-packages\django\db\models\base.py", line 879, in _do_insert
return manager._insert([self], fields=fields, return_id=update_pk,
File "D:\Studio\Python\REST\elections\env\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
.....
.....
File "D:\Studio\Python\REST\elections\env\lib\site-packages\django\db\backends\sqlite3\base.py", line 303, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: main.vote_choice__old
[08/Aug/2021 17:09:09] "POST /polls/6/choices/19/vote/ HTTP/1.1" 500 193455
Я пытаюсь создать POST API для пользователей, чтобы они могли проголосовать за заданный выбор.
Но я продолжаю получать ошибку, описанную ниже.
В чем может быть проблема?
Заранее спасибо!
Вот класс голосования в serializer.py:
class VoteSerializer(serializers.ModelSerializer):
class Meta:
model = Vote
fields = '__all__'
<
class CreateVote(APIView):
serializer_class = VoteSerializer
def post(self, request, pk, choice_pk):
voted_by = request.data.get("voted_by")
data = {'choice': choice_pk, 'poll': pk, 'voted_by': voted_by}
serializer = VoteSerializer(data=data)
if serializer.is_valid():
vote = serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Вот класс CreateVote в apiviews.py:
Вот код шаблонов URL в файле urls.py:
urlpatterns = [
path("polls/<int:pk>/choices/<int:choice_pk>/vote/", CreateVote.as_view(), name="create_vote"),
]
А код моделей выглядит следующим образом в models.py:
class Vote(models.Model):
choice = models.ForeignKey(Choice, related_name='votes', on_delete=models.CASCADE)
poll = models.ForeignKey(Poll, on_delete=models.CASCADE)
voted_by = models.ForeignKey(User, on_delete=models.CASCADE)
class Meta:
unique_together = ("poll", "voted_by")