Forums

Duplicate entry ' ' for key 'PRIMARY' SQL=INSERT INTO ...

cyberrock 06 Jan, 2017
HI Bob,
I hope you had a great christmas and new years.

I have a problem similar to :
https://www.chronoengine.com/forums/posts/t101445/p357090/1062-duplicate-entry.html

I have built another DB save and for some reason, the "id" (primary) always wants to save as "127"

This issue i have had a number of times before but normally change the function of the site as a work around (This time, i am unable to do it.) OR delete and rebuild the table which in this case, it is a new table any way and was only built 2 hours ago.

I have check pretty much the whole site, including saved users and there is no mention of an "id" equal to 127. thought this is showing up in my debug from the form data array.

1062 - Duplicate entry '127' for key 'PRIMARY' SQL=INSERT INTO `#__Accounts` (`id`, `Booking_ID`) values ('334', 'C2948W');


This is private content



When the "rwxoq_Accounts" is saved (at the bottom) the debug even says it is saving as an increasing unique id. But in actual fact, DOES save as the value 127.

As previously mentioned, it looks like the "id" is coming from the previous form, however, there is no "id" element in the form. I have even created an id element with no value hoping to fix it, with no success.
I have also tried unset($form->data['id']); which also hasnt worked.

Any assistance is always appreciated🙂

regards

Ben
cyberrock 06 Jan, 2017
Sorry Bob.
Disregard.. I have just come across this article which seams to have solved it.

The MySQL duplicate entry 127 for key 1 error occurs when the primary key of a database or table is set to the TINYINT data or field type. A TINYINIT field type can have a maximum value of 128. When adding new records in the database, the primary key is incremented for each record added. If the size exceeds 128 for a TINYINT type primary key, the duplicate entry 127 for key 1 error will be shown. To solve the problem, the TINYINT data type of the primary key may be changed to INT or a different table command may be used to auto-increment the value of this field.

cyberrock 06 Jan, 2017
Reference: http://ccm.net/faq/983-duplicate-entry-127-for-key-1
This topic is locked and no more replies can be posted.