/admin/posts/post/add/ 整数超出范围的 Django DataError
Django DataError at /admin/posts/post/add/ integer out of range
当我在 Django Admin 中创建一个新的 post 时,我收到一个整数超出范围的错误。这是一个具有 Post 模型的 DRF 项目,该模型使用 UUIDField 作为主键的 id。似乎 ID 字段导致了问题,但我不明白 UUIDField 是如何越界的。标题或 URL 等剩余字段中的 None 可能超出范围。
当我在管理面板中创建一个新的 post 时,我在单击“保存”按钮后收到此错误消息:
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
这是模型:
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)
... ...
我查看了各种答案,但找不到整数超出范围问题的答案。跟踪显示以下消息:
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:
您的跟踪显示问题与 taggit 库有关。我在你的 post 模型上没有看到标签字段,但如果你有,请尝试将其删除,进行迁移并重试。
当我在 Django Admin 中创建一个新的 post 时,我收到一个整数超出范围的错误。这是一个具有 Post 模型的 DRF 项目,该模型使用 UUIDField 作为主键的 id。似乎 ID 字段导致了问题,但我不明白 UUIDField 是如何越界的。标题或 URL 等剩余字段中的 None 可能超出范围。
当我在管理面板中创建一个新的 post 时,我在单击“保存”按钮后收到此错误消息:
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
这是模型:
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)
... ...
我查看了各种答案,但找不到整数超出范围问题的答案。跟踪显示以下消息:
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:
您的跟踪显示问题与 taggit 库有关。我在你的 post 模型上没有看到标签字段,但如果你有,请尝试将其删除,进行迁移并重试。