S
S
Siimple2018-07-30 07:41:16
SQL
Siimple, 2018-07-30 07:41:16

How to fix SQL error?

Hello! When adding a product in the OpenCart admin panel, an error pops up from the database.

Fatal error: Uncaught exception 'Exception' with message 'Error: Duplicate entry '400-74' for key 'PRIMARY'<br />Error No: 1062<br />INSERT INTO oc_product_to_store SET product_id = '400', store_id = '74'' in /var/www/u0430319/data/www/siimple.ru/system/library/db/mysqli.php:40 Stack trace: #0 /var/www/u0430319/data/www/siimple.ru/system/library/db.php(45): DB\MySQLi->query('INSERT INTO oc_...') #1 /var/www/u0430319/data/www/storage/modification/admin/model/catalog/product.php(18): DB->query('INSERT INTO oc_...') #2 [internal function]: ModelCatalogProduct->addProduct(Array) #3 /var/www/u0430319/data/www/storage/modification/system/engine/loader.php(248): call_user_func_array(Array, Array) #4 [internal function]: Loader->{closure}(Array, Array) #5 /var/www/u0430319/data/www/siimple.ru/system/engine/proxy.php(47): call_user_func_array(Object(Closure), Array) #6 /var/www/u0430319/data/www/storage/modification/admin/controller/catalog/product.php(52): Proxy->__call('addProduct', Array) #7 /var/www/u0430319/data/www/storage/m in /var/www/u0430319/data/www/siimple.ru/system/library/db/mysqli.php on line 40

Previously, I made queries through the database, not through INSERT , and REAPLACE after which I can’t add products through the admin panel, it gives an error.
If I understand correctly, he swears that such a key already exists. Due to the fact that I added manually through REPLACE, he stopped counting. Please let me know if there is any solution to this problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
poniyur, 2018-07-30
@Simple

It seems that product_id and store_id were set as PRIMARY KEY when creating the table, which means that they must be unique. This error indicates that there is already a record with the values ​​product_id = '400', store_id = '74'.
Such decisions can help:
1. To change PRIMARY KEY for the table.
2. Do not try to insert a duplicate as you are doing now
3. Use replace again

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question