我正在尝试删除已经发生的数据库中的事件.我的脚本如下.
在**的行上,我收到一个错误
AttributeError: type object 'events' has no attribute 'query'
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这一问题?谢谢!
Base = automap_base()
# engine, suppose it has two tables 'user' and 'address' set up
engine = create_engine("DB_URL")
# reflect the tables
Base.prepare(engine, reflect=True)
# mapped classes are now created with names by default
# matching that of the table name.
Event = Base.classes.events
User = Base.classes.users
**events = Event.query.filter(end_time < datetime.now())**
session = Session(engine)
session.delete(events)
session.commit()
Run Code Online (Sandbox Code Playgroud)
你没有调用query()你的映射类,你调用query()你的session对象:
Base = automap_base()
# engine, suppose it has two tables 'user' and 'address' set up
engine = create_engine("DB_URL")
# reflect the tables
Base.prepare(engine, reflect=True)
# mapped classes are now created with names by default
# matching that of the table name.
Event = Base.classes.events
User = Base.classes.users
session = Session(engine)
selected_events = session.query(Event).filter(Event.end_time < datatime.now())
selected_events.delete()
session.commit()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3919 次 |
| 最近记录: |