magento 2.2.3 Integrity constraint violation: 1062 Duplicate entry '18274-0-1' for key 'PRIMARY' - magento

On a Magento 2.2.3 instance after migrating data from Magento 1 via migration tool we're getting the following error in exceptions.log. The shop works fine, however this errors are still around and I can't really pinpoint it down. Any ideas for an approach?
[2018-10-01 09:00:08] main.CRITICAL: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '18274-0-1' for key 'PRIMARY', query was: INSERT INTO catalog_product_index_price_temp SELECT catalog_product_index_price_final_temp.entity_id, catalog_product_index_price_final_temp.customer_group_id, catalog_product_index_price_final_temp.website_id, catalog_product_index_price_final_temp.tax_class_id, catalog_product_index_price_final_temp.orig_price AS price, catalog_product_index_price_final_temp.price AS final_price, catalog_product_index_price_final_temp.min_price, catalog_product_index_price_final_temp.max_price, catalog_product_index_price_final_temp.tier_price FROM catalog_product_index_price_final_temp {"exception":"[object] (Magento\Framework\Exception\LocalizedException(code: 0): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '18274-0-1' for key 'PRIMARY', query was: INSERT INTO catalog_product_index_price_temp SELECT catalog_product_index_price_final_temp.entity_id, catalog_product_index_price_final_temp.customer_group_id, catalog_product_index_price_final_temp.website_id, catalog_product_index_price_final_temp.tax_class_id, catalog_product_index_price_final_temp.orig_price AS price, catalog_product_index_price_final_temp.price AS final_price, catalog_product_index_price_final_temp.min_price, catalog_product_index_price_final_temp.max_price, catalog_product_index_price_final_temp.tier_price FROM catalog_product_index_price_final_temp at /.../public_html/vendor/magento/module-catalog/Model/Indexer/Product/Price/Action/Row.php:32, Magento\Framework\DB\Adapter\DuplicateException(code: 1062): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '18274-0-1' for key 'PRIMARY', query was: INSERT INTO catalog_product_index_price_temp SELECT catalog_product_index_price_final_temp.entity_id, catalog_product_index_price_final_temp.customer_group_id, catalog_product_index_price_final_temp.website_id, catalog_product_index_price_final_temp.tax_class_id, catalog_product_index_price_final_temp.orig_price AS price, catalog_product_index_price_final_temp.price AS final_price, catalog_product_index_price_final_temp.min_price, catalog_product_index_price_final_temp.max_price, catalog_product_index_price_final_temp.tier_price FROM catalog_product_index_price_final_temp at /.../public_html/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:555, Zend_Db_Statement_Exception(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '18274-0-1' for key 'PRIMARY', query was: INSERT INTO catalog_product_index_price_temp SELECT catalog_product_index_price_final_temp.entity_id, catalog_product_index_price_final_temp.customer_group_id, catalog_product_index_price_final_temp.website_id, catalog_product_index_price_final_temp.tax_class_id, catalog_product_index_price_final_temp.orig_price AS price, catalog_product_index_price_final_temp.price AS final_price, catalog_product_index_price_final_temp.min_price, catalog_product_index_price_final_temp.max_price, catalog_product_index_price_final_temp.tier_price FROM catalog_product_index_price_final_temp at /.../public_html/vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:235, PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '18274-0-1' for key 'PRIMARY' at /.../public_html/vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:228)"} []

Related

Integrity constraint violation: 1052 Column 'created_at' in order clause is ambiguous

$banks_transactions = DB::table('finance_banking_transactions')
->join('finance_banks', 'finance_banking_transactions.bank_id', "=", 'finance_banks.id')
->latest()->paginate(20);
How do i solve the error SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in order clause is ambiguous (SQL: select * from `finance_banking_transactions` inner join `finance_banks` on `finance_banking_transactions`.`bank_id` = `finance_banks`.`id` order by `created_at` desc limit 20 offset 0)" and I have the column
Because you use join, you need to specify latest().
for example, latest('finance_banking_transactions.created_at'), or instead using latest(), you can use orderBy('finance_banking_transactions.created_at')

I have a problem with my foreign key in Laravel

I am getting this error in my laravel migration:
SQLSTATE[HY000]: General error: 1005 Can't create table
krada.#sql-2d10_cc (errno: 150 "Foreign key constraint is
incorrectly formed" ) (SQL: alter table posts add constraint
posts_category_id_foreign foreign key (category_id) references
categories (id) on dele te cascade)
SQLSTATE[HY000]: General error: 1005 Can't create table
krada.#sql-2d10_cc (errno: 150 "Foreign key constraint is
incorrectly formed" )

Laravel observer Update Event in not Triggering

I used this in my update function:
$qty = $request->input('checked_out_qty');
DB::table('consumables')->decrement('remaining_qty',$qty );
i keep getting this error:
"SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (fixed.consumables_histories, CONSTRAINT 251075_5c35eb169cb40 FOREIGN KEY (checked_out_qty_id) REFERENCES consumables (id) ON DELETE CASCADE) (SQL: insert into consumables_histories (consumables_id, checked_out_qty_id, checked_out_by_id, status_id, location_id, assigned_to_id, updated_at, created_at) values (1368, 6, 1, 1, 1, , 2019-02-03 08:08:34, 2019-02-03 08:08:34))
but when u refresh the second time, the decrement still happens. what could i be doing wrong?

laravel framework webservice error

I am just doing web service for laravel framework, so below error is displayed, I don't know which type of error
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'city' in where clause is ambiguous (SQL: SELECT MIN(room_prize)MIN,MAX(room_prize)MAX from `abserve_hotel_rooms` as `ar` JOIN `abserve_hotels` as `h` ON `ar`.`hotel_id` = `h`.`hotel_id` WHERE 1 AND `city` ="madurai" AND `country` ="india")
You forgot table alias to the fields city and country

Passing an id to other controller

$job->created_by = $input['created_by'];
I want to pass user id in this array which is in other table what should I do?
The field is a foreign key.
When I run this it throws an exception
SQLSTATE[23000]: Integrity constraint violation: 1452
Cannot add or update a child row: a foreign key constraint fails
(`freight`.`jobs`, CONSTRAINT `approved_by` FOREIGN KEY (`created_by`)
REFERENCES `users` (`id`))
(SQL: insert into `jobs`
(`company_id`, `origin`, `commodity`, `destination`,
`created_by`, `approved_by`, `date`, `carrier`, `consolidator`,
`overseas_agt`, `prepaid_fob`, `free_time`, `wt_pcs`,
`updated_at`, `created_at`)
values (2, , , , asdsadasdsad, asdsadasdsad, , , , , , , ,
2015-11-26 07:32:02, 2015-11-26 07:32:02)
)
You have initialize the field as unsigned in the DB Migration.
as:
$table->integer('user_id')->unsigned();
Here user_id is a primary key of another table.
Alter the table and run migration again.
It will work definitely.
I found what I did wrong I have to give the id of the user that is currently active the correct way is as follow
$job->created_by = \Auth::user()->id;

Resources