I have create custom module to create custom option with the reference of this "https://meetanshi.com/blog/create-custom-options-programmatically-in-magento-2/" page.

I'm getting bellow error for this "$option->save();" method.

a:4:{i:0;s:277:"SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0-0' for key 'CATALOG_PRODUCT_OPTION_TYPE_PRICE_OPTION_TYPE_ID_STORE_ID', query was: INSERT INTO catalog_product_option_type_price (option_type_id, store_id, price, price_type) VALUES (?, ?, ?, ?)";i:1;s:7500:"#0 /app/vendor/magento/framework/DB/Statement/Pdo/Mysql.php(95):

I have already try with reindex and FOREIGN_KEY_CHECKS, but still getting error.

  • Is there any extension or a fresh Magento version? – Khoa TruongDinh Sep 20 '18 at 6:37
  • it's my custom plugin, i have upgrade magento version from 2.1.6 to 2.1.14 after that i'm getting error – Jimit Bhavsar Sep 20 '18 at 6:47

please remove catalog_product_option_type_price backup table if you have

or if you have whole databse backup then this error will come

  • how can we remove core table.this is not proper answer – Rv Singh Sep 20 '18 at 6:45
  • I am saying that if you have take backup i am not talking about original table – Rutvee Sojitra Sep 20 '18 at 6:46
  • @RutveeSojitra , i can't delete that table as there are lost off data which is related to other products. – Jimit Bhavsar Sep 20 '18 at 6:49
  • First you check that catalog_product_option_type_price any backup or duplicate table exist there? Then think about this case I am not talking about original table... if you have duplicate of that table – Rutvee Sojitra Sep 20 '18 at 6:51
  • @Rutvee, i have done as you suggest, now showing this error: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (main.catalog_product_option, CONSTRAINT CAT_PRD_OPT_PRD_ID_CAT_PRD_ENTT_ROW_ID FOREIGN KEY (product_id) REFERENCES catalog_product_entity (row_id) ON DELETE CASCADE), query was: INSERT INTO catalog_product_option (product_id, type, is_require, sort_order) VALUES (?, ?, ?, ?)";i:1;s:6317:"#0 /app/vendor/magento/framework/DB/Statement/Pdo/Mysql.php(95): Zend_Db_Statement_Pdo->_execute(Array) – Jimit Bhavsar Sep 20 '18 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.