0

I have the above error.

First of all I'm trying to fully understand what it means.

Secondly I've tried investigating my tables in my database and the following query returns zero results as I understand that the error is a primary key related issue.

SELECT DISTINCT TABLE_NAME ,column_name 
FROM INFORMATION_SCHEMA.key_column_usage 
WHERE TABLE_SCHEMA IN ('dosiv_querta');

Here is the statement that throws the error.

INSERT INTO `ps_product_shop` (`id_product`, `id_category_default`, `id_tax_rules_group`, `on_sale`, `online_only`, `ecotax`, `minimal_quantity`, `price`, `wholesale_price`, `unity`, `unit_price_ratio`, `additional_shipping_cost`, `customizable`, `text_fields`, `uploadable_files`, `active`, `redirect_type`, `id_product_redirected`, `available_for_order`, `available_date`, `condition`, `show_price`, `indexed`, `visibility`, `cache_default_attribute`, `advanced_stock_management`, `date_add`, `date_upd`, `pack_stock_type`, `id_shop`) VALUES ('1', '32', '1', '0', '0', '0', '1', '38.99', '0', '', '0', '0', '0', '0', '0', '1', '', '0', '1', '0000-00-00', 'new', '1', '0', 'both', '0', '0', '2015-08-21 00:31:40', '0000-00-00', '3', '1')
Michal K
  • 225
  • 2
  • 9
  • 17
  • you're doing your insert wrong, or forgot to set `auto_increment` on your id field. – Marc B Aug 21 '15 at 16:20
  • Possible duplicate of http://stackoverflow.com/questions/14628269/error-code-1062-duplicate-entry-1-for-key-primary – mituw16 Aug 21 '15 at 16:21
  • There's nothing wrong with your PK. On the contrary, the fact that your PK is rock solid is what's preventing you from inserting duplicate data. – Álvaro González Aug 21 '15 at 16:23
  • The statement isn't trying to insert anything, it is just querying the tables in the database with columns that use keys. It could be that there are no tables using keys. Try `show tables in dosiv_querta;` Then `show create table some_table_that_uses_keys;` to verify that the primary key has been set for the table. – TeasingDart Aug 21 '15 at 16:34
  • The statement above is not the statement that is generating the error, correct? Could you also show the statement that is generating the error. I have seen this error when using a join where the joined table also has a column that is used as a primary key for the first table. – TeasingDart Aug 21 '15 at 16:39
  • Okay thanks will work on that and get back. I appreciate your assistance. – Michal K Aug 21 '15 at 17:04
  • Okay Ive updated the question with the original query. – Michal K Aug 21 '15 at 17:24

1 Answers1

1

It sounds like you're trying to insert a new record with a value of 1 in the primary key column. Since the primary key needs to be unique, it won't let you insert the record. Here's a simple example that reproduces the issue:

mysql> CREATE TABLE TestPrimary (
         ColOne INT NOT NULL,
         ColTwo VARCHAR(255) NULL,
         PRIMARY KEY(ColOne)
       ) ENGINE=InnoDB;
Query OK, 0 rows affected (0.02 sec)

mysql> 
mysql> INSERT INTO TestPrimary (ColOne,ColTwo) VALUES (1,"blah");
Query OK, 1 row affected (0.01 sec)

mysql> 
mysql> INSERT INTO TestPrimary (ColOne,ColTwo) VALUES (1,"boo");
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
voipdaddy
  • 73
  • 6