While creating product, at the last step after retrieving for a time, Magento gives following error-:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1922-1' for key 'IDX_STOCK_PRODUCT'
What I am doing is, by capturing product id, I am putting it's entry in custom table. I have connected to Magento database externally.
Surprisingly data is inserted in both Magento's base table & also in Custom table but why it is giving me that error after product saving...?
I cleared cache, browser cookies. Also remove /var/cache, /var/session. still giving error. Can anybody suggest a solution?
In order to remedy this error, you will need to insert the value that you attempted to place in the child table into the parent table first. Once inserted as a parent row, you can go back and insert the value into the child table.
It just simply means that the value for column country on table comments you are inserting doesn't exist on table country_type or you are not inserting value for country on table user.
Integrity constraint violations occur when an insert, update, or delete statement violates a primary key, foreign key, check, or unique constraint or a unique index.
the message means you are doing another insert with the same combination of columns that are part of the IDX_STOCK_PRODUCT, which seams to be defined as UNIQUE. If it is so, it doesn't allow to enter same combination (it seems like it consists of two fields) twice.
If you are inserting records, make sure you are picking brand new record id or that the combination of record id and the other column is unique.
Without detailed table structure and your code, we can hardly guess whats going wrong.
Many time this error is caused when you update a product in your custom module's observer as shown below.
class [NAMESPACE]_[MODULE NAME]_Model_Observer
{
/**
* Flag to stop observer executing more than once
*
* @var static bool
*/
static protected $_singletonFlag = false;
public function saveProductData(Varien_Event_Observer $observer)
{
if (!self::$_singletonFlag) {
self::$_singletonFlag = true;
$product = $observer->getEvent()->getProduct();
//do stuff to the $product object
// $product->save(); // commenting out this line prevents the error
$product->getResource()->save($product);
}
}
Hence whenever you save your product after updating some properties in your module's observer use $product->getResource()->save($product)
instead of $product->save()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With