sqlalchemy.exc.InternalError: (pymysql.err.InternalError)(3065,“ORDER BY…this与DISTINCT不兼容的表达式#1”)

2024-05-13 01:25:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我在用烧瓶和炼金术。下面是我的表单.py公司名称:

    temp = [('All','All Motions')]
    motions = db.session.query(Motion_Type.code, Motion_Type.description).distinct(Motion_Type.code).filter(Motion_Type.id == Motion.id).order_by(Motion_Type.order.asc()).all()
    for motion_type in motions:
        temp.append((Motion_Type.description,Motion_Type.description))
    return temp

但是,当我运行项目时,错误是:

sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (3065, "Expression #1 of ORDER BY clause is not in SELECT list, references column 'xxx.motion_type.order' which is not in SELECT list; this is incompatible with DISTINCT")

我不确定我的问题是否可以追溯到模型.py,或者是因为我的mySQL数据库设置不正确(即需要主键/外键的表或列没有设置好)

基本上,我需要知道错误发生的原因,这样我才能纠正它。初学者。在


Tags: inpyidistype错误codeorder