sqlalchemy.exc.InternalError: (cymysql.err.InternalError)-
程序员文章站
2022-06-13 22:00:48
...
代码
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