mysql insert data given IntegrityError: (1062, "Duplicate entry 'xx' for key 'xxxxx'")

 

 

1. Problem Description

MySQL error when inserting data suggests the following:

IntegrityError: (1062, "Duplicate entry 'xx' for Key 'XXXXX'")
2. Analysis

According to error, we can generally get the following information:

1.IntegrityError indicates that the field type in MySQL is: integer.

2.Duplicate Entry: "Duplicate" - something that is an exact copy of something else. So this means that: xxxxx for key already exists a value "xx", so when inserting duplicate values ​​will prompt the error. Generally due to a unique set field caused.

I later discovered before setting up a joint primary key, but a primary key when inserting data I are used, resulting in no insert


3. Solution

(1) delete the existing value, reinserted.

(2) or a field to allow duplicate values.

(3) determining whether the inserted already exists before making

 

Transfer from https://blog.csdn.net/qq_42091922/article/details/87253653

Guess you like

Origin www.cnblogs.com/z-x-y/p/11261926.html