Page 1 of 1

importing data from csv (phpmyadmin error: duplicate entry)

PostPosted: Thu Sep 18, 2014 11:57 am
by k8inmd
hi - i was able to get an excel spreadsheet imported but each line error ed so nothing came up - here's the error message when I try again. I am only trying to upload description and price...

Error
SQL query:

INSERT INTO `private_catonsvillecm` ( `description` , `price` )
VALUES (

'Center Smoked Cut Ham Steaks', '$9.75 '
)
MySQL said: Documentation

#1062 - Duplicate entry '' for key 'PRIMARY'

Please advise
Kathleen

Re: importing data from csv

PostPosted: Thu Sep 18, 2014 12:24 pm
by support
Item codes are mandatory and must be unique, so you must also specify values for the code column. The error you got is telling you that, just not so obviously. When you leave off code, it tries to set them all to NULL, but it can't because they must be unique, so it fails on the second row trying to set an item code to NULL when there already is one.

Also, I am moving this topic to the Product database subforum, since that is for phpMyAdmin and other database questions.

Re: importing data from csv (phpmyadmin error: duplicate ent

PostPosted: Thu Sep 18, 2014 12:33 pm
by k8inmd
so in my excel spreadsheet that has two columns, description and price, how do I get it an item code? is there an auto generate options for sequential number or an easy way to do this?

Re: importing data from csv (phpmyadmin error: duplicate ent

PostPosted: Thu Sep 18, 2014 12:48 pm
by support
Your spreadsheet program should be able to add an autoincrement column, but I'm not exactly sure how.

How many items are there? If not too many, you could just invent them yourself? Generally it is better not to use an autoincrement, because then in the next database you may have different items sharing the same item code as the last version of the database. This can cause problems if your order is not completely empty (archived, without any recurring orders) when you update the database.

The vendor doesn't use or doesn't give you their own item codes?

Re: importing data from csv (phpmyadmin error: duplicate ent

PostPosted: Mon Nov 23, 2015 7:32 pm
by andrewd
Having the same issue. Every time i change an item code, re-save the csv file, (after getting the error message) and re-import it, up pops the same error for a different product. After using the find function in excel, i'm not able to find any duplicate codes anywhere for the products showing error codes. But once i change the product code it no longer hits on that product, it just goes to the next product that doesn't have a real duplicate, yet says it does.

Re: importing data from csv (phpmyadmin error: duplicate ent

PostPosted: Mon Nov 23, 2015 7:52 pm
by support
You should be clearing the database in between runs. If you aren't, then it leaves a partial import after each run, so the next import of the same csv file will hit a duplicate item on the very first item.

If you are clearing the database, then I'd ask, are you sure the item codes are unique in the file? Try sorting the csv file by item code, and then it should be easy to see the duplicates.

Re: importing data from csv (phpmyadmin error: duplicate ent

PostPosted: Mon Nov 23, 2015 8:04 pm
by andrewd
Thanks! I hadn't cleared out the last database. That makes sense. Appreciate the feedback. Any reference links on how to clear?

Re: importing data from csv (phpmyadmin error: duplicate ent

PostPosted: Mon Nov 23, 2015 11:19 pm
by support
Already e-mailed you this, but posting here for reference by other users who might read this topic in the future:

How to clear private database in phpmyadmin:
http://foodclub.org/wiki/Foodclub:Docum ... ew_file.3F