Django中的UUID字段(错误:运算符不存在:INTEGER=UUID) [英] UUIDField in Django (error:operator does not exist: integer = uuid)
本文介绍了Django中的UUID字段(错误:运算符不存在:INTEGER=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
请帮帮我。
推荐答案
我为这个问题找到了另一个解决方案如果您想使用uuid字段作为id,您需要在第一次迁移之前将此字段作为id转换缺失部分是因为您的id字段不会以适当的方式更改为uuidfield
这篇关于Django中的UUID字段(错误:运算符不存在:INTEGER=UUID)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文