django - Django中的UUIDField(错误:运算符不存在:整数= uuid)
问题描述
我想使用 uuid 字段作为我的 id(主键),但它有问题,我无法修复它......
这是我的模型
class Course(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
title = models.CharField(max_length=90)
description = models.TextField()
author = models.CharField(max_length=60)
image = models.ImageField(upload_to='courses/images')
intro_video = models.FileField(upload_to='courses/videos')
free = models.BooleanField(default=False)
price = models.CharField(max_length=60, blank=True)
completed = models.BooleanField(default=False)
duration = models.CharField(max_length=30, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title
当我尝试添加新课程时,它给了我这个错误
ProgrammingError at /admin/courses/course/add/
operator does not exist: integer = uuid
LINE 1: ..., "created_at" = NULL WHERE "courses_course"."id" = 'a130811...
^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
Exception Type: ProgrammingError
Exception Value: operator does not exist: integer = uuid
我的数据库是postgresql
请帮我。
解决方案
利用 :
id=models.CharField(primary_key=True,default=uuid.uuid4, editable=False, max_length=36)
推荐阅读
- app-startup - TomEE 在初始化虚拟目录时花费大量时间
- ios - 如何从 UIActivityViewController swift 打开一项
- javascript - Ajax 帖子和 Fetch 帖子
- docker - 使用主机网络时无法从 Internet 访问 docker 容器
- python - 从 django orm 获取硬查询。Django 休息框架
- c# - itext hml2pdf:在 2.1.0 版之后,在源 html 中声明字体不起作用
- c++ - 在 C++ 中使用 UTF-8 解析 XML
- ipywidgets - ipywidgets:GridspecLayout 网格间隙似乎不起作用
- json - 使用结构读取 JSON
- vb6 - 组件 MSCOMCTL.OCX 或其依赖项之一未正确注册