I want to use uuid field as my id (primary key) but there is something wrong with it and i can’t fix it
this is my model
class Cart(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
created_at = models.DateTimeField(auto_now_add=True)
class CartItem(models.Model):
cart = models.ForeignKey(Cart, on_delete=models.CASCADE , related_name='items')
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.PositiveSmallIntegerField()
class Meta:
unique_together = [['cart'], ['product']]
This Is MY Serializer.py
class CartItemSerializer(serializers.ModelSerializer):
class Meta:
model = Cart
fields = ['id', 'product', 'quantity']
class CartSerializer(serializers.ModelSerializer):
id = serializers.UUIDField(read_only=True)
items = CartItemSerializer(many=True)
class Meta:
model = Cart
fields = ['id', 'items']
And My Views.py is
class CartViewSet(CreateModelMixin, RetrieveModelMixin, GenericViewSet):
queryset = Cart.objects.prefetch_related('items__product').all()
serializer_class = CartSerializer
My database Is postgres Sql
my error is
django.db.utils.ProgrammingError: operator does not exist: bigint = uuid
LINE 1: ..."store_cartitem" WHERE "store_cartitem"."cart_id" IN ('2abf9...
^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.