Mysql prompts Duplicate entry... for key error Solution

Source: Internet
Author: User

Duplicate entry... for key... cause of error: this error occurs because the unique value of the primary key is repeated. This error is reported once the unique value of the primary key is repeated during database modification and insertion, if multiple primary keys exist in the table, this error is still reported during table operations.

For example, Duplicate entry for key 3 indicates that the table's 3rd fields have a unique index restriction. You need to insert other non-repeated values or remove the unique attribute of the field.

View an instance

If phpMyAdmin exists on your site, you can also use phpMyAdmin to check the tables with errors in your databaseWhether the current auto-increment value of the auto-increment field is the same as the maximum value of the Self-increment field in the tableIf they are the same, this error will occur.

How to check?

1) Go To Your phpMyAdmin and select the database with an error on the left.

2) Select the table with an error and find the auto-increment field of the table. The field marked with auto_increment is the auto-increment field of the table.

3) Click Browse, sort the auto-increment fields in descending order, and write down the current maximum value of the auto-increment field.

4) Click the operation at the top of the page to see the auto_increment item in "Table options". This is the value of the auto-increment field of the data to be inserted next time, if the value is the same as the maximum value of the current auto-increment field, an error is returned. Therefore, the value is changed to greater than the maximum value of the current auto-increment field, click "execute" to solve the problem.
In the example, the maximum value of the current auto-increment field is 54, and the value of the auto-increment field of the next data to be inserted is 55.

Another case is that the value of the auto-increment field has reached the maximum value of this field, that is, it cannot be increased. In this case, the same error message is displayed. The error message of my friend Forum mentioned above is exactly the reason. The data type of the auto-increment field is mediumint (8). Due to data problems, the value of this field exceeds the maximum value of 16777215! Correct the error data to solve the problem.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.