我的models.py包含
class Patient(models.Model):
cpf_id = models.CharField(max_length=15, unique=True)
name_txt = models.CharField(max_length=50)
nr_record = models.AutoField(primary_key=True)
数据库是postgresql。
当我尝试用
选择对象时>>> Patient.objects.get(nr_record=1)
我收到错误
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 151, in get
return self.get_queryset().get(*args, **kwargs)
.
.
.
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
ProgrammingError: operator does not exist: character varying = integer
LINE 1: ...d" FROM "quiz_patient" WHERE "quiz_patient"."nr_record" = 1
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
我是Django-python的新手。但直到我知道models.Autofield是整数类型。
搜索了网络,但尽管发布了相同的错误消息,但没有发现任何类似我的问题。
答案 0 :(得分:1)
问题肯定在于您的数据库。也许你有一个以前版本的模型,其中nr_record不是一个整数?
尝试删除数据库中的nr_record列并再次添加。