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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章