我的 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 是整数类型。
搜索网络,但尽管有相同错误消息的帖子,但没有找到与我的问题类似的问题。
请您参考如下方法:
问题肯定出在您的数据库上。也许您有一个模型的先前版本,其中 nr_record 不是整数?
尝试删除数据库中的 nr_record 列并重新添加。
