# 异常方法 Book.objects.all().delete() # 对于大型数据集,可能会失效 Book.objects.raw('''delete from book''') # 也失效了
文档说明: Note that delete() is the only QuerySet method that is not exposed on a Manager itself. This is a safety mechanism to prevent you from accidentally requesting Entry.objects.delete(), and deleting all the entries. If you do want to delete all the objects, then you have to explicitly request a complete query set:
#解决方案 book = Book.objects.all() book.delete() # 又是返回值的问题。。。。。
报错提示: MySQLdb.err.ProgrammingError: nan can not be used with MySQL
# 解决方案 data.fillna(value=0) # 用0填充
data = Book.objects.raw(sql_)
注意:sql_语句中查询的列必须包含主键,data的类型为rawqueryset()