Jump to content

[SOLVED] Duplicate entry '1' for key 1


tsilenzio

Recommended Posts

Okay i am building a database and it loads the tables with no problems and fills in all the data accept the last one:

 

Tables:

//

// Table Structure for races

//

CREATE TABLE races(

RaceID        INT(2)        UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,

RaceName    TINYTEXT    NOT NULL,

RaceDesc    TINYTEXT    NOT NULL

);

 

I have the page display every query it does and this is the last 5 lines:

INSERT INTO loc (LocID, LocName, LocDesc) VALUES ('0', 'Arnolds', 'Description');

 

INSERT INTO shops (ShopID, ShopName, ShopLoc, ShopDesc) VALUES ('0', 'Shop', '0', 'Normal Shop');

 

INSERT INTO races (RaceID, RaceName, RaceDesc) VALUES ('0', 'Causation', '');

 

INSERT INTO races (RaceID, RaceName, RaceDesc) VALUES ('1', 'African American', ''); Couldnt send query:

 

Duplicate entry '1' for key 1

 

Any ideas on how to fix this problem? If you are confused then let me know and i will explain as best as i can! thank you in advance!!

Link to comment
Share on other sites

primary keys always start with a cardinality of 1 - that is, the value of a primary key for the first inserted record will always be one.  therefore your first INSERT into races creates a record with a raceID of 1, and you're trying to insert another one right after it with the same key.  if you just drop RaceID from the field and values list, MySQL will take care of assigning it for you.

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.