I am trying to use UUID as a primary key on a model and it throws an Overflow error when using redirect.
I looked online for similar problems as I assume it should be quite frequent that people want to do that. I came accross: https://github.com/jazzband/django-taggit/issues/679
So I installed dajngo-taggit and I tried to add the snippet on this link in my code but the problem remains.
Below is my current code using the snippet:
[models.py]
from django.db import models
from taggit.managers import TaggableManager
from taggit.models import GenericUUIDTaggedItemBase, TaggedItemBase
class Person(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
# ...
class UUIDTaggedItem(GenericUUIDTaggedItemBase, TaggedItemBase):
# If you only inherit GenericUUIDTaggedItemBase, you need to define
# a tag field. e.g.
# tag = models.ForeignKey(Tag, related_name="uuid_tagged_items", on_delete=models.CASCADE)
class Meta:
verbose_name = _("Tag")
verbose_name_plural = _("Tags")
class Car(models.Model):
person = models.ForeignKey(Person, null=True, on_delete=models.SET_NULL)
brand = models.CharField(max_length=50)
colour = models.CharField(max_length=50)
# ...
[urls.py]
# ...
urlpatterns = [
# ...
path("<uuid:pk>/car/<int:id>/", CarDetail.as_view(), name="car_detail"),
# ...
]
And the error I get is:
OverflowError at /en/person/c8c91051-5773-4c69-9587-92b468186db7/car/1/
Python int too large to convert to SQLite INTEGER
Would you have any ideas of what I could try to fix it? I have been on this issue for quite some time. Thank you!!