尝试按今天的日期筛选时发生sqlalchemy.exc.argumenterror
能够打印date out date.today(),但当我将其与sqlalchemy一起使用时,它的抛出属性错误会告诉我们需要约束
我试过的代码
def daily_Fitness() :
result = Fitness.query.filter_by ( date.today () )
for result in result :
result.append ( {"Yoga" : Fitness.activity_type_1 , "Jogging" : Fitness.activity_type_2 ,
"Walking" : Fitness.activity_type_2 ,
"time" : Fitness.fitness_time ,
"comments" : Fitness.comments
} )
return result
输出
Traceback (most recent call last):
File "C:\Users\siveg\anaconda3\lib\site-packages\sqlalchemy\sql\schema.py", line 124, in _init_items
spwd = item._set_parent_with_dispatch
AttributeError: 'datetime.date' object has no attribute '_set_parent_with_dispatch'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:/Users/siveg/gitProject/python-project-template/python-project-template/application/models.py", line 10, in <module>
class Food(db.Model) :
File "C:/Users/siveg/gitProject/python-project-template/python-project-template/application/models.py", line 16, in Food
date=db.Column (date.today(), unique=True , nullable=False )
File "C:\Users\siveg\anaconda3\lib\site-packages\sqlalchemy\sql\schema.py", line 1636, in __init__
self._init_items(*args)
File "C:\Users\siveg\anaconda3\lib\site-packages\sqlalchemy\sql\schema.py", line 126, in _init_items
util.raise_(
File "C:\Users\siveg\anaconda3\lib\site-packages\sqlalchemy\util\compat.py", line 211, in raise_
raise exception
sqlalchemy.exc.ArgumentError: 'SchemaItem' object, such as a 'Column' or a 'Constraint' expected, got datetime.date(2021, 7, 27)
代码解释
假设获取当前日期特定表的数据
预期产量
Able to successfully fetch the data entered from the table as specified
{"Yoga" : Fitness.activity_type_1 , "Jogging" : Fitness.activity_type_2 ,
"Walking" : Fitness.activity_type_2 ,
"time" : Fitness.fitness_time ,
"comments" : Fitness.comments}
暂无答案!
目前还没有任何答案,快来回答吧!