当前位置:网站首页>Duplicate entry 'XXX' for key 'XXX.PRIMARY' solution.
Duplicate entry 'XXX' for key 'XXX.PRIMARY' solution.
2022-07-31 04:52:00 【geejkse_seff】
Error in mysql insert: Duplicate entry 'XXX' for key 'XXX.PRIMARY'
An error occurred while inserting data today
com.jfinal.plugin.activerecord.ActiveRecordException:com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:Duplicate entry 'xxxxxx' for key 'xxxx.PRIMARY'On the Internet, it said that the primary key conflicted, but the database did not. After clearing all the data, or deleting the table, the same error was reported after rebuilding.
…
…
…
Final result scheme:
- Option 1: Set the primary key to auto-increment, suitable for the primary key to be int type (my primary key is varchar)
- Option 2: Change insert into table name() values(); to: insert ignore into table name() values(); (problem solving)
MySQL provides Ignore to avoid repeated insertion of data.
IGNORE :
If there is a record that causes a unique key conflict, the record will not be inserted into the database.
MySQL INSERT IGNORE Please go to: MySQL INSERT IGNORE
Reason: This is because a unique index is set for the corresponding field in the table. When we perform logical deletion, there is no real deletion, but it is only marked as deleted.
When we add it again, becauseThere is a limitation of unique index, which makes us unable to add successfully, so an error is reported.
Solution 1:
If allowed, remove the unique index limitation of this field in the database, so that the backend can perform logical deletion,Even if the field value of the record marked for deletion is equal to the field value when adding, because there is no unique index restriction, it can be added normally
Solution 2:
It is not necessary to remove the unique index restriction in the database, but when the back-endWhen developing the delete operation, the SQL statement for physical deletion (real deletion) is executed instead of logical deletion. At the same time, the backend uses logical judgment to query whether the same number exists in the database. If it exists, it is not allowed.Add, if it doesn't exist, you can add it
Let me introduce myself first. The editor graduated from Jiaotong University in 2013. I worked in a small company and went to big factories such as Huawei and OPPO. I joined Ali in 2018, until now.I know that most junior and intermediate java engineers want to upgrade their skills, they often need to explore their own growth or sign up to study, but for training institutions, the tuition fee is nearly 10,000 yuan, which is really stressful.Self-learning that is not systematic is very inefficient and lengthy, and it is easy to hit the ceiling and the technology stops.Therefore, I collected a "full set of learning materials for java development" for everyone. The original intention is also very simple. I hope to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.Add the business card below to get a full set of learning materials
边栏推荐
- Musk talks to the "virtual version" of Musk, how far is the brain-computer interaction technology from us
- ERROR 1819 (HY000) Your password does not satisfy the current policy requirements
- The third is the code to achieve
- Unity框架设计系列:Unity 如何设计网络框架
- C语言表白代码?
- ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your
- 递归实现汉诺塔问题
- 打造基于ILRuntime热更新的组件化开发
- Two address pools r2 are responsible for managing the address pool r1 is responsible for managing dhcp relays
- BUG destroyer!!Practical debugging skills are super comprehensive
猜你喜欢
随机推荐
[R language] [3] apply, tapply, lapply, sapply, mapply and par function related parameters
Recursive implementation of the Tower of Hanoi problem
聚变云原生,赋能新里程 | 2022开放原子全球开源峰会云原生分论坛圆满召开
Lua,ILRuntime, HybridCLR(wolong)/huatuo热更新对比分析
MySQL事务隔离级别详解
ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your
重磅 | 基金会为白金、黄金、白银捐赠人授牌
three.js 制作3D相册
XSS靶场(三)prompt to win
MySQL优化:从十几秒优化到三百毫秒
SOLVED: After accidentally uninstalling pip (two ways to manually install pip)
[C language] Detailed explanation of operators
打造基于ILRuntime热更新的组件化开发
ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)
Unity shader forge和自带的shader graph,有哪些优缺点?
Sql解析转换之JSqlParse完整介绍
Error EPERM operation not permitted, mkdir 'Dsoftwarenodejsnode_cache_cacach Two solutions
【py脚本】批量二值化处理图像
MySQL database addition, deletion, modification and query (detailed explanation of basic operation commands)
Three oj questions on leetcode









