天天看點

【無标題】sqlalchemy版本不對,導緻ORM操作出問題,_mapper_args__ = {“order_by“: country_code}報錯unexpected keyword argum

sqlalchemy版本不對,導緻ORM操作出問題,mapper_args_ = {“order_by”: country_code}報錯unexpected keyword argument ‘order_by’

mapper_args = {“order_by”: country_code}報錯unexpected keyword argument ‘order_by’,是什麼原因呢

【無标題】sqlalchemy版本不對,導緻ORM操作出問題,_mapper_args__ = {“order_by“: country_code}報錯unexpected keyword argum

TypeError: init() got an unexpected keyword argument ‘order_by’

這個報錯原因:

新版本的 sqlalchemy 丢棄了 mappter_args 當中設定的方法

解決方法一

應當用 db.query().order_by() 直接在 Query 對象後面顯示地調用 order_by 函數

解決方法二:降低sqlalchemy

使用指令在cmd視窗安裝舊的sqlalchemy版本

先打開cmd視窗

【無标題】sqlalchemy版本不對,導緻ORM操作出問題,_mapper_args__ = {“order_by“: country_code}報錯unexpected keyword argum

使用指令下載下傳舊的版本

pip install sqlalchemy==1.1.2      

試試上面版本,看看有沒有那個函數

如果沒有,就試試其他函數,

下面是sqlalchemy的版本:

【無标題】sqlalchemy版本不對,導緻ORM操作出問題,_mapper_args__ = {“order_by“: country_code}報錯unexpected keyword argum

全部是sqlalchemy的版本

你可以使用 pip install sqlalchemy==錯誤的版本,在cmd視窗就會提示你所有的版本