sqlalchemy.exc.InternalError: (cymysql.err.InternalError)-

代码

class Gift(Base):
    id = Column(Integer, primary_key=True)
    user = relationship('User')
    uid = Column(Integer, ForeignKey('user.id'))
    isbn = Column(String(15), nullable=False)
    launched = Column(Boolean, default=False)

    @classmethod
    def recent(cls):
        recent_gift = Gift.query.filter_by(
            launched=False).group_by(
            Gift.isbn).order_by(
            desc(Gift.create_time)).limit(
            current_app.config['PECENT_BOOK_COUNT']).distinct().all()
        return recent_gift

在执行调用rencent函数的时候,函数内部有一个链式调用,运行报错,显示无法进行group_by操作。

报错

标题-(1055, "Expression #1 of SELECT list is noSELECT list is not in GROUP BY clause and contains nonaggregated column…

原因

MySQL 5.7.5 之后 sql_mode 默认值是 “only_full_group_by”,不能执行group_by查询

解决

第一步

找到MySQL的安装目录编辑“my.ini”的配置文件,然后在最后一行添加配置

sql-mode="STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ZERO_DATE,NO_ZERO_IN_DATE,NO_AUTO_CREATE_USER"

第二步

重启MySQL服务


问题解决~

https://blog.csdn.net/FateDant/article/details/96965029

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值