错误原因:在mysql版本5.7.5之后mysql_mode默认值是"only_full_group_by",不能执行group_by查询:
案例说明:ubuntu
res = db.session.query(table_name). \
filter(table_name.id == id). \
group_by(table_name.id). \
all()
报错提示:
sqlalchemy.exc.InternalError: (cymysql.err.InternalError) (1055, "Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column)
解决问题:
cd /ect/mysql/mysql.conf.d
sudo vim mysqld.cnf
在文件底部添加:
sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
保存!!!
重启数据库生效
:
service mysql restart;