0

我正在dreamhost上构建Django +MySQL,但遇到错误消息:
渲染时出现异常:(1064,“您的SQL语法有错误;请查看与您的MySQL服务器版本相对应的手册以获取正确的语法使用') ORDER BY tag. used_countDESC, tag. nameASC' 附近的第 1 行")

我仔细追踪,发现错误splot与以下函数有关:
有人能帮我检查一下这段代码有什么问题吗?

 def get_tags_by_questions(self, questions):
    question_ids = []
    for question in questions:
        question_ids.append(question.id)

    question_ids_str = ','.join([force_unicode(id) for id in question_ids])
    related_tags = self.extra(
            tables=['tag', 'question_tags'],
            where=["tag.id = question_tags.tag_id AND question_tags.question_id IN (" + question_ids_str + ")"]
    ).distinct()

    return related_tags
4

1 回答 1

2

是否有可能没有问题,在这种情况下 SQL 将包含类似"WHERE question_id IN ()"which would not be valid SQL 的内容。

于 2009-06-30T15:02:53.920 回答