当前位置:网站首页>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
边栏推荐
- Hand in hand to realize the picture preview plug-in (3)
- ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)解决办法
- Minio上传文件ssl证书不受信任
- Visual studio shortcuts that improve efficiency, summary (updated from time to time)
- From scratch, a mirror to the end, a pure system builds a grasscutter (Grasscutter)
- sql语句-如何以一个表中的数据为条件据查询另一个表中的数据
- three.js make 3D photo album
- MySQL基础操作
- MySQL优化:从十几秒优化到三百毫秒
- MySQL事务隔离级别详解
猜你喜欢
MySQL数据库备份
HCIP第十天_BGP路由汇总实验
【云原生】DevOps(五):集成Harbor
矩池云快速安装torch-sparse、torch-geometric等包
WeChat applet uses cloud functions to update and add cloud database nested array elements
MySQL database addition, deletion, modification and query (detailed explanation of basic operation commands)
从零开始,一镜到底,纯净系统搭建除草机(Grasscutter)
centos7安装mysql5.7
BUG消灭者!!实用调试技巧超全整理
ENSP, VLAN division, static routing, comprehensive configuration of Layer 3 switches
随机推荐
DVWA安装教程(懂你的不懂·详细)
HCIP Day 10_BGP Route Summary Experiment
WPF WPF 】 【 the depth resolution of the template
重磅 | 开放原子校源行活动正式启动
ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)
Open Source Smart Future | 2022 OpenAtom Global Open Source Summit OpenAtom openEuler sub-forum was successfully held
input输入框展示两位小数之precision
CentOS7 安装MySQL 图文详细教程
unity2d小游戏
XSS shooting range (3) prompt to win
The Vue project connects to the MySQL database through node and implements addition, deletion, modification and query operations
A complete introduction to JSqlParse of Sql parsing and conversion
MySQL database installation (detailed)
sql语句之多表查询
unity2d game
Sql解析转换之JSqlParse完整介绍
益智类游戏关卡设计:逆推法--巧解益智类游戏关卡设计
Doris学习笔记之监控
[Cloud Native] DevOps (5): Integrating Harbor
参考代码系列_1.各种语言的Hello World