Part-2 Django Course - Designing and Implementing a Shopping Cart API - 5th video
after POSTing a cart item there’s a step of adding the UUID in the database when I do that step I get the error saying “Data too long for column ‘cart_id’ at row 1”. Here are some snippets:
This is image showes the dtype of the columns:
store/models.py:
class Cart(models.Model):
id = models.UUIDField(primary_key=True, default=uuid4)
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']]
store/views.py:
class CartViewSet(CreateModelMixin, RetrieveModelMixin, GenericViewSet):
queryset = Cart.objects.all()
serializer_class = CartSerializer
store/serializer.py
class CartSerializer(serializers.ModelSerializer):
id = serializers.UUIDField(read_only=True)
class Meta:
model = Cart
fields = ['id', 'items']
What should be done to avoid this error?