I wrote some code which adds stock data to a product. It runs fine on my testing DB. Now I started testing the code on the customers DB and this error comes up:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '449-1' for key 'UNQ_MAGENTO_CATALOGINVENTORY_STOCK_ITEM_PRODUCT_ID_STOCK_ID', query was: INSERT INTO
magento_cataloginventory_stock_item
(product_id
,stock_id
,qty
,min_sale_qty
,use_config_min_sale_qty
,max_sale_qty
,use_config_max_sale_qty
,is_in_stock
,low_stock_date
,manage_stock
,use_config_manage_stock
,stock_status_changed_auto
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
This is the code:
$product->setStockData(array(
'use_config_manage_stock' => 0, //'Use config settings' checkbox
'manage_stock' => 1, //manage stock
'min_sale_qty' => 1, //Minimum Qty Allowed in Shopping Cart
'max_sale_qty' => 999, //Maximum Qty Allowed in Shopping Cart
'is_in_stock' => 1, //Stock Availability
'qty' => 999 //qty
)
);
The error comes up when I am saving the product like this:
$product->save();
Without the stock code, the product can be saved. I checked the database import file I have and it has the forgeign key checks in it, so that cant be the problem. I am running Magento 1.9.
Any ideas?
Thanks!