问题
I am getting this error:
TypeError: 'BaseQuery' object is not callable
Here is my code:
companies = Company.query.all()
return Company.query(func.count(Company.id))
I need to find out number of rows in Company model. Please help!
回答1:
Company.query
isnt callable there. If you've already selected all your companies with companies = Company.query.all()
, why not simply use len(companies)
?
If you dont want/need to retrieve the data, you can get just the count with Company.query.count()
来源:https://stackoverflow.com/questions/18058438/typeerror-basequery-object-is-not-callable-flask