当前位置:网站首页>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
边栏推荐
- Unity shader forge和自带的shader graph,有哪些优缺点?
- The MySQL database installed configuration nanny level tutorial for 8.0.29 (for example) have hands
- 1. Get data - requests.get()
- Unity框架设计系列:Unity 如何设计网络框架
- 【debug锦集】Expected input batch_size (1) to match target batch_size (0)
- npm、nrm两种方式查看源和切换镜像
- Duplicate entry ‘XXX‘ for key ‘XXX.PRIMARY‘解决方案。
- Unity教程:URP渲染管线实战教程系列【1】
- ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)
- [Linear Neural Network] softmax regression
猜你喜欢

BUG消灭者!!实用调试技巧超全整理

Go language study notes - dealing with timeout problems - Context usage | Go language from scratch

聚变云原生,赋能新里程 | 2022开放原子全球开源峰会云原生分论坛圆满召开

The third is the code to achieve

On Governance and Innovation | 2022 OpenAtom Global Open Source Summit OpenAnolis sub-forum was successfully held

DVWA安装教程(懂你的不懂·详细)

Unity打灵狐者

产学研用 共建开源人才生态 | 2022开放原子全球开源峰会教育分论坛圆满召开

30 Years of Open Source Community | 2022 Open Atom Global Open Source Summit 30 Years of Open Source Community Special Event Held Successfully

MySQL事务(transaction) (有这篇就足够了..)
随机推荐
重磅 | 开放原子校源行活动正式启动
mysql使用on duplicate key update批量更新数据
高斯分布及其极大似然估计
论治理与创新 | 2022开放原子全球开源峰会OpenAnolis分论坛圆满召开
手把手实现图片预览插件(三)
MySQL数据库备份
A complete introduction to JSqlParse of Sql parsing and conversion
Unity打灵狐者
Heavyweight | The Open Atomic School Source Line activity was officially launched
MySQL database backup
【R语言】【3】apply,tapply,lapply,sapply,mapply与par函数相关参数
MySQL优化:从十几秒优化到三百毫秒
Sun Wenlong, Secretary General of the Open Atom Open Source Foundation |
Mysql应用安装后找不到my.ini文件
Gaussian distribution and its maximum likelihood estimation
Musk talks to the "virtual version" of Musk, how far is the brain-computer interaction technology from us
HCIP Day 10_BGP Route Summary Experiment
Sql解析转换之JSqlParse完整介绍
mysql数据库安装(详细)
[C language] Detailed explanation of operators