Flask-SQLAlchemy如何删除单个表中的所有行 [英] Flask-SQLAlchemy how to delete all rows in a single table

查看:3624
本文介绍了Flask-SQLAlchemy如何删除单个表中的所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Flask-SQLAlchemy删除单个表中的所有行?

寻找类似这样的内容:

 >>> users = models.User.query.all()
>>> models.db.session.delete(users)

#但出错:UnmappedInstanceError:Class'__builtin __。list'未映射


解决方案

试试 $ b

  models.User.query.delete()

From 文档返回删除的行数,不包括任何级联。


How do I delete all rows in a single table using Flask-SQLAlchemy?

Looking for something like this:

>>> users = models.User.query.all()
>>> models.db.session.delete(users)

# but it errs out: UnmappedInstanceError: Class '__builtin__.list' is not mapped

解决方案

Try delete:

models.User.query.delete()

From the docs: Returns the number of rows deleted, excluding any cascades.

这篇关于Flask-SQLAlchemy如何删除单个表中的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆