[Django](1093, "You can't specify target table 'fee_details_invoices' for update in FROM clause") 错误
dele_id = Fee_details_invoices.objects.filter(fee_detail_id__in=fee_id_list, return_type='2').values_list('fee_detail_id', flat=True)
Fee_details_invoices.objects.filter(fee_detail_id__in=dele_id).delete()
报错:
django.db.utils.DatabaseError: (1093, "You can't specify target table 'fee_details_invoices' for update in FROM clause")
错误分析解决:
第一行代码的意思是获取某些条件行的某个字段
第二行代码去删除这些行包括这个字段值的记录
依照文档第一行代码返回的应该是一个list啊 见文档
>>> Entry.objects.values_list('id', flat=True).order_by('id')
[1, 2, 3, ...]
第二行代码的输入參数也是一个list啊 见文档
Entry.objects.filter(id__in=[1, 3, 4])
为啥错了呢?
通过debug看到dele_id的结果把
dele_id
[]
type(dele_id)
<class 'django.db.models.query.ValuesListQuerySet'>
看到了把,尽管打印出来是个list的样子,事实上不是list类型
解决:第二行语句把dele_id强转即可了
Fee_details_invoices.objects.filter(fee_detail_id__in=list(dele_id)).delete()
有时候是不能看表象的。
即使是动态语言,类型不一致也会出现非常多坑。
[Django](1093, "You can't specify target table 'fee_details_invoices' for update in FROM clause") 错误的更多相关文章
- Mysql update in报错 [Err] 1093 - You can't specify target table 'company_info' for update in FROM clause
Mysql update in报错 解决方案: [Err] 1093 - You can't specify target table 'company_info' for update in FRO ...
- [Err] 1093 - You can't specify target table 's' for update in FROM clause
[Err] 1093 - You can't specify target table 's' for update in FROM clause 执行SQL DELETE from book WHE ...
- MySQL中执行sql语句错误 Error Code: 1093. You can't specify target table 'car' for update in FROM clause
MySQL中执行sql语句错误 Error Code: 1093. You can't specify target table 'car' for update in FROM clause 201 ...
- mysql 1093 - You can't specify target table 'xx表' for update in FROM clause
为了修复节点表某批次数据的用户数据,做出了以下尝试: , name , , )); 执行:[Err] 1093 - You can't specify target table 'zs_work_ap ...
- 关于mysql 5.7版本“报[Err] 1093 - You can't specify target table 'XXX' for update in FROM clause”错误的bug
不同于oracle和sqlserver,mysql并不支持在更新某个表的数据时又查询了它,而查询的数据又做了更新的条件,因此我们需要使用如下的语句绕过: , notice_code ) a) ; 本地 ...
- MySQL - 1093异常 - You can't specify target table 't' for update in FROM clause
有一个表示地区的表,表结构与数据大概如下表. ID NAME PARENT_ID 1 中国 2 广东省 1 3 广州市 2 4 荔湾区 3 5 越秀区 3 6 番禺区 3 7 小谷围街道 6 现为了查 ...
- ERROR 1093 (HY000): You can't specify target table 'test' for update in FROM clause
MySQL执行更新语句报错: 更新语句:UPDATE test SET state=50 WHERE num IN(SELECT num FROM test WHERE state=60): 报错:E ...
- mysql用查询结果当删除的判断条件进行删除报错1093 You can't specify target table解决方法
mysql用查询结果当删除的判断条件进行删除报错1093 You can't specify target table解决方法 #分开两个sql执行正常的语句,只保留最新1000条数据,删掉1000条 ...
- 1093 - You can't specify target table 'account' for update in FROM clause
目的:查询一张表的相同的两条数据,并删除一条数据. 分析 先查询出相同的数据,然后删除 查询相同的数据 SELECT a.id FROM account a GROUP BY a.username H ...
随机推荐
- PS2: 这篇文章中的图片绘图工具使用的是Dia (sudo apt-get install dia)。据说yEd也很不错。
SBCL编译过程 - O.Nixie的专栏 - 博客频道 - CSDN.NET PS2: 这篇文章中的图片绘图工具使用的是Dia (sudo apt-get install dia).据说yEd也很不 ...
- 公司内网Debian Server上的openvpnserver搭建并通过SSH隧道转发到广域网
因为戴维营公司在长沙的学员,研发人员和北京的研发人员须要协同研发,故须要让北京的兄弟们增加到长沙办公室的内网,訪问版本号 管理server,于是採用在内网server上搭建一个OpenVPN服务,并把 ...
- 让自己的软件实现拖拽打开文件(使用WM_DROPFILES消息和DragQueryFile函数)
//声明 protected procedure WMDROPFILES(var Msg : TMessage); message WM_DROPFILES; //实现 procedure TForm ...
- 《转载》值得学习!Google的编程样式指南
原网址:http://www.csdn.net/article/2012-10-12/2810689-Google-styleguide 本文分享了Google众多编程语言的样式指南,其中包括C语言. ...
- [Android]Eclipse的使用
1.取消Eclipse拼写检查 General -> Editors -> Text Editors -> Spelling 取消enable spell checking 前面的勾 ...
- Python学习入门基础教程(learning Python)--5.3 Python写文件基础
前边我们学习了一下Python下如何读取一个文件的基本操作,学会了read和readline两个函数,本节我们学习一下Python下写文件的基本操作方法. 这里仍然是举例来说明如何写文件.例子的功能是 ...
- Visual Prolog 的 Web 专家系统 (8)
GENI核心 -- 推理引擎(2)流量控制 1.阐述fail."!"而回溯 与其他语言相比,,Prolog最大的特点.这是回溯机制. 回溯机制,还有的主要手段2个月,首先,通过使用 ...
- [置顶] C++学习书单
关于C++的书太多了,很容易让人没有头绪.一直想整理下,把这些书列个书单出来,直到今天才动手.希望我的经验能给后来的初学者一点帮助. 1.<C++程序设计教程> 钱能 很多学校把这本书选做 ...
- jQuery Mobile 是创建移动 web 应用程序的框架。
jQuery Mobile jQuery Mobile 是创建移动 web 应用程序的框架. jQuery Mobile 适用于所有流行的智能手机和平板电脑. jQuery Mobile 使用 HTM ...
- HTC one/M7电信802d 毒蛇ViperOne2.1.0/高级毒蛇工具/完美root,精简/更多自定义,稳定,流畅ROM
ROM版本 HTC One/M7 802d ROM作者 雪狼团队·大盛 http://weibo.com/DaShengdd Android版本 Android 4.2.2 创建日期 2013.09. ...