小编Jor*_*aro的帖子

有效的UUID不是有效的UUID

我遇到一个非常奇怪的问题,例如,我得到一个有效的UUID并不是一个有效的UUID:

'fd31b6b5-325d-4b65-b496-d7e4d16c8a93' is not a valid UUID.

File "/opt/python/run/venv/lib/python3.4/site-packages/django/db/models/fields/__init__.py" in get_db_prep_value
  2371.                 value = uuid.UUID(value)

File "/usr/lib64/python3.4/uuid.py" in __init__
  134.             hex = hex.replace('urn:', '').replace('uuid:', '')


      During handling of the above exception ('UUID' object has no attribute 'replace'), another exception occurred:
Run Code Online (Sandbox Code Playgroud)

我的模型有一个UUIDField作为pk,错误似乎是随机发生的,直到我重新启动服务器后该错误才会消失,当服务器重新启动时它可以正常工作,所以我在这里有点迷失了,我使用django 1.10.7,亚马逊AWS中的PostgreSQL 9.6.3,Python 3.4.3。

编辑:

引起麻烦的模型

class ReciboTransaccion(models.Model):    
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    ingreso = models.ForeignKey('banco.BaseTransaccion', related_name='recibo_ingreso',
                                on_delete=models.PROTECT,
                                null=True, blank=True,
                                editable=False)
    egreso = models.OneToOneField('banco.BaseTransaccion', related_name='recibo_egreso',
                                  on_delete=models.PROTECT,
                                  null=True, blank=True,
                                  editable=False)
    fecha = models.DateTimeField(auto_now_add=True)
Run Code Online (Sandbox Code Playgroud)

模型“ BaseTransaccion”也具有

id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
Run Code Online (Sandbox Code Playgroud)

编辑2: …

python django postgresql amazon-web-services django-rest-framework

6
推荐指数
1
解决办法
1888
查看次数