save() prohibited to prevent data loss due to unsaved related object 'item_n
问题描述:
save() prohibited to prevent data loss due to unsaved related object 'item_no
原因分析:
原来的目的是保存数据时同步另一个表,不存在新增,存在更新,但是当不存在新增时,关联外键item_no的信息还没有保存,就开始编辑关联表,导致数据丢失。
解决办法:
等主表的数据保存成功后再去同步编辑关联表,所以我们需要将super().save()的保存命令放到字表update_or_create之前。
def save(self, force_insert=False, force_update=False, using=None,
update_fields=None):
super().save()
IM003D1Model.objects.update_or_create(item_code=self.item_no + '-' + self.item_unit.code,
unit_ratio=1,
su_price=0,
cu_price=0,
cu_price_vip=0,
defaults={'item_no': self,
'item_unit': self.item_unit}
)
save() prohibited to prevent data loss due to unsaved related object 'item_n的更多相关文章
- 解决gpg failed to sign the data fatal: failed to write commit object解决方案
今天有位新同事在comit代码的时候一直报这个错误: gpg failed to sign the data fatal: failed to write commit object. 看到网上说gp ...
- git问题:gpg failed to sign the data fatal: failed to write commit object问题
今天用版本控制工具git提交时一直出现的问题:gpg failed to sign the data fatal: failed to write commit object, gpg是一个加密软件 ...
- 问题:MongoDB C# driver异常:Truncation resulted in data loss
问题描述: 原因分析: MongoDB C#驱动在读取数据记录遇到数值类型字段时,如果没有设置允许截断,将抛出TruncationException. 解决方法: [BsonRepresentatio ...
- [ html canvas getImageData Object.data.length ] canvas绘图属性 getImageData Object.data.length 属性讲解
<!DOCTYPE html> <html lang='zh-cn'> <head> <title>Insert you title</title ...
- [SAP ABAP开发技术总结]数据引用(data references)、对象引用(object references)
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- 九、Django之ORM
一.ORM概述 用于实现面向对象编程语言里不同类型系统的数据之间的转换,换言之,就是用面向对象的方式去操作数据库的创建表以及增删改查等操作. 到目前为止,当我们的程序涉及到数据库相关操作时,一般操作流 ...
- Django之ModelForm操作
一.ModelForm的使用 顾名思义,ModelForm就是将Model与Form进行绑定,Form有自动生成表单的作用,但是每一个forms字段需要自己手动填写,而Model就是数据库表包含了所有 ...
- Building Applications with Force.com and VisualForce(Dev401)(十一):Designing Applications for Multiple Users: Proseving Data Quality
Dev401-012:Proseving Data Quality Universal Containers Scenario1.Universal Containers(UC) wants to e ...
- Visual Studio 2013 osg
1>------ Rebuild All started: Project: ZERO_CHECK, Configuration: Debug x64 ------1> Checking ...
- Adaptive partitioning scheduler for multiprocessing system
A symmetric multiprocessing system includes multiple processing units and corresponding instances of ...
随机推荐
- Unity图片转存及读取
[code]csharpcode: /// <summary> /// 加载图片 /// </summary> private Sprite LoadTexture(strin ...
- Cryptanalyzing and Improving a Novel Color Image Encryption Algorithm Using RT-Enhanced Chaotic Tent Maps
Cryptanalyzing and Improving a Novel ColorImage Encryption Algorithm Using RT-EnhancedChaotic Tent M ...
- DES & 3DES 简介 以及 C# 和 js 实现【加密知多少系列】
〇.简介 1.DES 简介 DES 全称为 Data Encryption Standard,即数据加密标准,是一种使用密钥加密的块算法,1977 年被美国联邦政府的国家标准局确定为联邦资料处理标准( ...
- 解放AI生产力——ComfyUI
最近状态不好,所以这几天基本没干什么,就分享一下和AI绘画工作流有关的东西吧. 此前我都没有抱着一种教学的心态来写博客,因为我所掌握的东西实在太过简单,只要一说大家就会了,我害怕我在人群里失去自己的特 ...
- 【实战】SpringBoot+uniapp+uview打造H5+小程序+APP入门学习的聊天小项目
JavaDog Chat v1.0.0 基于SpringBoot+uniapp简单通讯聊天软件 项目介绍 JavaDog Chat 简单通讯聊天软件是基于SpringBoot+MybatisPlus+ ...
- 用 Go 剑指 Offer 11. 旋转数组的最小数字
已知一个长度为 n 的数组,预先按照升序排列,经由 1 到 n 次 旋转 后,得到输入数组.例如,原数组 nums = [0,1,4,4,5,6,7] 在变化后可能得到:若旋转 4 次,则可以得到 [ ...
- abc285G
ABC 285 G - Tatami Solution 网络流 网格图是一个天然二分图, 可以按 横纵坐标之和 的奇偶性将相邻两格分属于左部和右部. 记'?' 或 '2' 的格子为待匹配点, 记横纵坐 ...
- Ubuntu2204部署容器引擎Containerd
为什么使用containerd? 使用containerd的原因主要有两点吧,第一个是docker在k8s1.24以后不再支持,如果需要在k8s中继续使用docker作为容器引擎,我们需要额外部署cr ...
- 随手记:Redis 部署到linux上面后,本地无法连接
修改redis的配置文件 redis.conf 1. bind 设置为 0.0.0.0 2. protected-mode 设置为no (也就是关闭保护模式) 3. daemonize 设置 ...
- C# 系统菜单弹出框方向
右键菜单,tootip等弹出时,弹出的位置经常在左侧,使用体验不好. 弹出方向有左对齐和右对齐 SystemParameters.MenuDropAlignment 当右对齐时,值为false 可以在 ...