phpMyAdmin error #1062 - Duplicate entry '1' for key 1
Asked Answered
T

5

6

I am not sure why I am getting this error #1062 - Duplicate entry '1' for key 1 cany any one help explain what it means. Thanks

Terry answered 22/7, 2010 at 17:8 Comment(0)
M
6

More than likely your column is set to be Unique, and you're trying to input a row with an ID that already exists in your table.

Manifestation answered 22/7, 2010 at 17:12 Comment(1)
Setting the column to auto_increment and not inserting a value when inserting the row (letting it auto populate) would be the best fix. Or you could see the last ID in your table though, and increment it by one for your value.Manifestation
H
4

You are probably trying to insert a record with the ID (or some other field) 1 set, while such a record already exists in the table. The field that is the primary key must have a unique value for each record.

Homoeo answered 22/7, 2010 at 17:12 Comment(2)
I am doing a drupal to wordpress conversion and when I get to this part of the conversion INSERT INTO lceating_wrdp1.wp_terms (term_id, name, slug, term_group) SELECT d.tid, d.name, REPLACE(LOWER(d.name), ' ', '-'), 0 FROM wrdp1.term_data d INNER JOIN wrdp1.term_hierarchy h USING(tid) it throws this error #1062 - Duplicate entry '1' for key 1 I set the primary key to be unique.Terry
@Terry you may have to set the key back to non-unique for the first import, or unset the IDs in the table you're copying from. Whether that is safe to do is impossible to tell without knowing the data.Homoeo
L
2

I think you're trying to insert '1' to a unique key field that already has a '1' value

Leveridge answered 22/7, 2010 at 17:13 Comment(3)
I am doing a drupal to wordpress conversion should i do a drop the table content and then try again?Terry
Hate to ask another question but, I dropped the table and started from scratch I am not getting the duplicate any more but I am getting this error #1062 - Duplicate entry 'lc-plans' for key 2 does that mean that I am trying to add two of the 'lc-plans' field? thanksTerry
yes, the error you are getting its the same (#1062) but in a different field, you shouls check the db schema of wordpress (constraints, primary keys, unique keys, etc.) before trying to insert data.Leveridge
D
1

The problem is related with your file - you are trying to create a DB using a copy - at the top of your file you will find something like this:

CREATE DATABASE IF NOT EXISTS *THE_NAME_OF_YOUR_DB* DEFAULT CHARACTER SET latin1 COLLATE latin1_general_ci; USE *THE_NAME_OF_YOUR_DB*;

and I'm sure that you already have a DB with this name - IN THE SAME SERVER - please check.

Doubler answered 25/8, 2013 at 9:13 Comment(0)
L
0

You need to add primary key with the group in which one primary key must be unique value. e.g. if a table has 4 columns id, name, address, group_id where group_id has duplicate value , if I want to add group_id as primary then that should be in a group consist with id and group_id

Loosestrife answered 10/5, 2013 at 3:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.