SqlAlchemy. TypeError: filter_by() takes exactly 1 argument (2 given)

前端 未结 1 1841
后悔当初
后悔当初 2021-01-12 21:54

I upgraded sqlalchemy from 0.7 to 0.9.6. After upgrade I am getting the following error:

TypeError
TypeError: filter_by() takes exactly 1 argument (2 given)
         


        
相关标签:
1条回答
  • 2021-01-12 22:30

    Without seeing code, obviously you are calling filter_by wrong. filter_by takes only the implicit self (the 'exactly 1 argument' meaning exactly 1 positional argument) and optional keyword arguments. You are providing filter_by another positional argument, possibly a dictionary.

    The syntax is:

    query.filter_by(column1=value, column2=value)
    

    Whereas for filter:

    query.filter(Model.column1 == value, Model.column2 == value)
    
    0 讨论(0)
提交回复
热议问题