Zen Cart Logo
Forums / General Questions / 1062 Duplicate entry '261228-7443 'for key' PRIMARY '

1062 Duplicate entry '261228-7443 'for key' PRIMARY '

Views: 1,251

Results 1 to 4 of 4
4 Jun 2013, 4:45 PM
#1
crb_style avatar

crb_style

New Zenner

Join Date:
Jun 2011
Posts:
4
Plugin Contributions:
0

1062 Duplicate entry '261228-7443 'for key' PRIMARY '

Hi I'm working as an import on db Zen Cart and a procedure fails me quite often so I tried to do this:
try {
$ result = $ db-> Execute ($ query);
echo "Data successfully inserted. Insert ID:". $ VALUE_products_id;
} Catch (Exception $ e) {
echo $ e-> getMessage ();
}

But it does not work and the error:
1062 Duplicate entry '261228-7443 'for key' PRIMARY '
in:
[INSERT INTO products ...
still comes out as the fact is that stops me throughout the procedure. I would skip this thing what can I do?

4 Jun 2013, 6:52 PM
#2
allthingsidleroy avatar

allthingsidleroy

New Zenner

Join Date:
May 2013
Posts:
38
Plugin Contributions:
0

Re: 1062 Duplicate entry '261228-7443 'for key' PRIMARY '

MySQL is telling you that you're trying to insert a Primary Key that already exists in the table. Primary Keys must be unique [1] and there can never be a duplicate.

What data are you trying to insert into what table and why?

[1] Unique key

6 Jun 2013, 9:47 AM
#3
crb_style avatar

crb_style

New Zenner

Join Date:
Jun 2011
Posts:
4
Plugin Contributions:
0

Re: 1062 Duplicate entry '261228-7443 'for key' PRIMARY '

allthingsidLeroy:

MySQL is telling you that you're trying to insert a Primary Key that already exists in the table. Primary Keys must be unique [1] and there can never be a duplicate.

What data are you trying to insert into what table and why?

[1] Unique key

I know that a primary key can not be duplicated, but when you import large files to an external customer with automatic procedures at night it can happen that the file that you're importing is therefore wrong to have such lines dupicate. This is a mistake, however, to ensure that the import procedure is solid should not interrupt the process but only report the error otherwise the shop the next morning will no catagories and or products for example.

6 Jun 2013, 1:06 PM
#4
allthingsidleroy avatar

allthingsidleroy

New Zenner

Join Date:
May 2013
Posts:
38
Plugin Contributions:
0

Re: 1062 Duplicate entry '261228-7443 'for key' PRIMARY '

crb_style:

. . . should not interrupt the process but only report the error otherwise the shop the next morning will no catagories and or products for example.

If you're running a query that contains an error, MySQL will generally interrupt the query, but the data inserted before the error should still be inserted. From the command-line, you can pass an argument (--force) which will force MySQL to keep going after errors. You might want to look at PHP's documentation to see how to pass this argument.

This information says that mysql_query (which I think Zen Cart uses) doesn't throw exceptions, but returns false. So, if you still want the php script to continue running after an error -- because you presumably had more queries -- then you'd have to check for false values.