MySQL Error: #1062 Duplicate entry ' ***′for Key 1 problem Solving method _mysql

Source: Internet
Author: User
Tags mysql manual
I changed the int type of ID to bigint, in fact, it may be better to change back. It is possible that an error occurred while backing up the database.

The development of the Web site backend system in the test process, this problem occurs:
Invalid query:duplicate entry ' 127′for key 1
SQL is:insert into ' kq_news ' (' Title ', ' Author ', ' Type ', ' Content ', ' Isdel ', ' adate ', ' Range ', ' Lang ') VALUES (' Donation activities ', ' Yuanying ', ' 3′, ', ' 0′,now (), ' 2′, ' CN '
Because it is the first time to encounter such a problem, Google a bit, similar problems n many, solutions have a lot of similarities, nothing more than the repair table (repair), MySQL repair tools Myisamchk tool repair. Tried it, and still did not solve it.

Then look at the data table structure:
Copy Code code as follows:

CREATE TABLE IF not EXISTS ' kq_news ' (
' Id ' tinyint (3) not NULL auto_increment,
' Title ' varchar (COLLATE) latin1_general_ci not NULL,
' Content ' text collate latin1_general_ci not NULL,
' Adate ' date not NULL,
' Isdel ' tinyint (1) Not NULL default ' 0′,
' Hits ' int (5) Not NULL default ' 0′,
' Author ' varchar collate latin1_general_ci not NULL,
' Type ' tinyint (1) Not NULL default ' 1′,
' Lang ' varchar (2) Collate latin1_general_ci not NULL,
' Range ' tinyint (1) Not NULL default ' 1′,
PRIMARY KEY (' Id ')
) Engine=myisam DEFAULT charset=latin1 collate=latin1_general_ci;

Finally understand that the original ID of this type of self-added field is mistaken! Convert the data type and it's done!

The MySQL manual was then opened and a description of the tinyint and smallint and int types was found:

tinyint[(M)] [UNSIGNED] [Zerofill]
A very small integer. The signed range is 128 to 127, and the unsigned range is 0 to 255.

smallint[(M)] [UNSIGNED] [Zerofill]
A small integer. The signed range is 32768 to 32767, and the unsigned range is 0 to 65535.

mediumint[(M)] [UNSIGNED] [Zerofill]
A medium sized integer. The signed range is 8388608 to 8388607, and the unsigned range is 0 to 16777215.

int[(M)] [UNSIGNED] [Zerofill]
A normal size integer. The signed range is 2147483648 to 2147483647, and the unsigned range is 0 to 4294967295.

integer[(M)] [UNSIGNED] [Zerofill]
This is a synonym for int.

bigint[(M)] [UNSIGNED] [Zerofill]
A large integer. The signed range is 9223372036854775808 to 9223372036854775807, and the unsigned range is 0 to
18446744073709551615.

I see!
That's why other online invalid query:duplicate entry ' 32767′for key 1 went wrong!
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.