我有我必须编写SQL查询的web2py应用程序。有一张名为作业的表格,其中我感兴趣的列是接收器。此栏包含已收到作业的学生列表。 这列由web2py错误:您可能需要添加明确的类型转换
创建我需要将这些列表值在另一个表比较列学生称为student_guardian_relation。
db.define_table('student_guardian_relation',
Field('student',db.auth_user, requires=IS_NULL_OR(IS_IN_DB(db(db.auth_user.user_role == UserRoles.Student),db.auth_user.id,'%(first_name)s %(last_name)s'))),
Field('guardian',db.auth_user, requires=IS_NULL_OR(IS_IN_DB(db(db.auth_user.user_role == UserRoles.Guardian),db.auth_user.id,'%(first_name)s %(last_name)s')))
)
但是,当我尝试这两个值进行比较,我得到一个错误,多数民众赞成写着:
< class 'psycopg2.ProgrammingError'> operator does not exist: text = integer LINE 1: ...rdian_relation, homework WHERE (homework.receiver = student_...^HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
这是我的代码呢:
print db(db.homework.receiver == db.student_guardian_relation.student).select(db.homework.receiver)
附加信息:
当我写:
print db().select(db.homework.receiver)
我得到了如图所示的接收器列表。 任何帮助将不胜感激。 谢谢!
DB中的某些东西是一个int,而某些东西是一个字符串,并且postgres告诉你它不能比较这两个东西......很难判断哪些是不能看到更多的代码, - 你可以发布实际的模型类吗? – kylewm 2015-02-07 07:20:22
接收者是一个列表,我想将它与int中的学生ID进行比较。 – MJB 2015-02-07 08:04:54