I'm getting an integer out of range error when I create a new post in Django Admin. This is DRF project with a Post model that uses a UUIDField as id which is the primary key. It seems like the ID field is causing the problem but I don't understand how the UUIDField can be out of bounds. None of the remaining fields like Title or URL could be out of range.
When I go to create a new post in the Admin dashboard, I get this error message after I click the Save button:
DataError at /admin/posts/post/add/
integer out of range
Request Method: POST
Request URL: http://localhost:8000/admin/posts/post/add/
Django Version: 3.0.7
Exception Type: DataError
Exception Value:
integer out of range
Exception Location: /Users/username/Desktop/Workspace/project-api/venv/lib/python3.7/site-packages/django/db/backends/utils.py in _execute, line 86
Python Executable: /Users/username/Desktop/Workspace/project-api/venv/bin/python
Python Version: 3.7.3
Here's the Model:
class UUIDModel(models.Model):
id = models.UUIDField(primary_key=True, editable=False, default=uuid.uuid4)
class Meta:
abstract = True
class TimeStampedUUIDModel(UUIDModel):
created_at = models.DateTimeField(auto_now_add=True, editable=False)
modified_at = models.DateTimeField(auto_now=True, editable=False)
class Meta:
abstract = True
class Post(TimeStampedUUIDModel):
creator = models.ForeignKey(User, on_delete=models.CASCADE, related_name="posts")
title = models.CharField(
_("Title"), max_length=255, blank=False, null=False)
description = models.TextField(
_("Description"), max_length=1500, blank=False, null=False)
url = models.URLField(_("URL"), unique=True,
max_length=155, blank=False, null=False)
country = models.CharField(
_("Country"), max_length=120, blank=False, null=False)
post_image = VersatileImageField(
"Post image",
blank=False,
null=False,
upload_to=post_image_directory,
ppoi_field="post_image_ppoi"
)
post_image_ppoi = PPOIField()
STATUS_DRAFT = "D"
STATUS_PUBLISHED = "P"
STATUSES = (
(STATUS_DRAFT, "Draft"),
(STATUS_PUBLISHED, "Published"),
)
status = models.CharField(blank=False, null=False, choices=STATUSES,
default=STATUS_DRAFT, max_length=2)
... ...
I've looked at various answers but can't find an answer to the integer out of range issue. The Trace shows the following message:
2020-08-18 10:03:44,953:[ERROR]:logger=django.request:request_id=a6d4549d7bfb42f2b780473bcc19ebdf message='Internal Server Error: /admin/posts/post/add/'
Traceback (most recent call last):
File "/Users/username/Desktop/Workspace/project-api/venv/lib/python3.7/site-packages/django/db/models/query.py", line 559, in get_or_create
return self.get(**kwargs), False
File "/Users/username/Desktop/Workspace/project-api/venv/lib/python3.7/site-packages/django/db/models/query.py", line 417, in get
self.model._meta.object_name
taggit.models.TaggedItem.DoesNotExist: TaggedItem matching query does not exist.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/username/Desktop/Workspace/project-api/venv/lib/python3.7/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.NumericValueOutOfRange: integer out of range
The above exception was the direct cause of the following exception:
Your trace shows that the issue is related to the taggit library. I don't see a tag field on your post model but if you have one, try removing it, make migrations and try again.