Jump to content

[SOLVED] cannot add new entry to db


kev wood

Recommended Posts

i am trying to add a new entry in a mysql db and keep getting this error.

 

Duplicate entry '127' for key 1

 

i have never seen this error before and dont know what it means.  anyone now where i can get an explanation of this error and maybe a pointer on how to get rid of this problem.

Link to comment
Share on other sites

no that is what i was thinking it would be but i was wrong.  well not entirely wrong any way. 

 

it is a website that i had not built so the db was not set up by me and not set up in the same way as i would have set it up.  the primary id had been set up as a tinyint and unknown to me until about 5 min ago a tiny int can only hold up to 128 pieces of information so it is 0 > 127 which equates to 128.

 

the db was already holding 127 rows so it could not add another row to the db so it was trying to add the new row in row 127 which already exists.

 

to fix the problem i have just changed the data type of the row to an int and it is all working again now.

 

well at least i have reached my daily goal already in learning something new.  i will now have a relaxing day since i have only been in for 2 hours. ha ha if only.

Link to comment
Share on other sites

i have just read something that said that a tinyint could only hold up to 127 pieces of information and the tinyint in the db had been set as a tinyint(4) and would not hold anymore information than 127 rows.

 

strange.  if you say it can hold up to 255 with a tinyint(3) why would it not go passed 127 for a tinyint(4).  is tinyint(4) the wrong syntax for this data type can it only be set as a tinyint(3).

 

 

Link to comment
Share on other sites

so from what i can see the db had been set up with a signed tinyint but the increment had started from 0 so it could have only ever got up to 127 as this is the highest number it can hold when it is a signed data type.

 

didnt think you could have that from what i have just been reading.  for what he had set the db up for i would have just used int for the id to start with.  i would not have had these problems to begin with and tinyint should not be used for a db as it is to small a number i feel. 

 

i had just found this page before your post.

 

http://www.codingforums.com/showpost.php?p=540233&postcount=6

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.