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 ...
随机推荐
- Checkmk监控工具使用手册
其实用法Checkmk官网文档很全面:https://docs.checkmk.com/latest/en/intro_setup.html 顺着beginner's guide章节看完基本就能上手, ...
- 痞子衡嵌入式:盘点国内RISC-V内核MCU厂商(2021年发布产品)
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是国内RISC-V内核MCU厂商(2021). 虽然RISC-V风潮已经吹了好几年,但2019年才是其真正进入主流市场的元年,最近国内大量 ...
- 阿里云镜像创建Spring Boot工厂
参考博客:https://blog.csdn.net/qq_40052237/article/details/115794368 http://start.aliyun.com
- maui BlazorWebView+本地html (vue、uniapp等都可以) 接入微信sdk 开发 Android app
首先添加微信sdk的绑定库 nuget 包:Chi.MauiBinding.Android.WeChat 项目地址:https://github.com/realZhangChi/MauiBindin ...
- smart rtmpd 服务器配置文件说明及优化方法介绍
---------------------------------------------------------------------------------------------------- ...
- redis.clients.jedis.exceptions.JedisConnectionException: Failed connecting to "xxxxx"
Java 连接 Redis所遇问题 1. 检查Linux是否关闭防火墙,或对外开放redis默认端口6379 关闭防火墙. systemctl stop firewalld 对外开放端口.firewa ...
- 逍遥自在学C语言 | 逻辑运算符
前言 一.人物简介 第一位闪亮登场,有请今后会一直教我们C语言的老师 -- 自在. 第二位上场的是和我们一起学习的小白程序猿 -- 逍遥. 二.构成和表示方式 逻辑运算符是用来比较和操作布尔值的运算符 ...
- pysimplegui之第一个程序,包括回调函数,事件,阻塞等待内容
自定义窗口 API 调用(您的第一个窗口) 总结一下:我遇到的坑, 比如拿输入框的内容的时候可以直接通过value[key] 几种窗口模式就是什么时候用timeout这个参数 关闭窗口可以的一边形式 ...
- [Linux/Apache Http]Apache Http(d)服务访问时报: 403 Forbidden You don't have permission to access /cdh/ on this server.
1 问题描述 http错误代码403:403 Forbidden 资源不可用.服务器理解客户的请求,但拒绝处理它.通常由于服务器上文件或目录的权限设置导致. 2 解决思路 胜利的果实: 确保关闭sel ...
- C++ 标准库 sort() / stable_sort() / partial_sort() 对比
C++ STL标准库中提供了多个用于排序的Sort函数,常用的包括有sort() / stable_sort() / partial_sort(),具体的函数用法如下表所示: 函数 用法 std::s ...