laravel framework webservice error - laravel

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

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')

vendor/laravel/framework/src/Illuminate/Database/Connection.php:678

SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value (SQL: insert into product_catagories (catagory_name, updated_at, created_at) values (Electronics, 2021-04-25 14:32:59, 2021-04-25 14:32:59))
How Can I solved this problem on a live server
Check your 'id' structure on your sql.
You got an error because 'id' field' doesn't have default value.
Also Make sure AUTO_INCREMENT checked

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous

When I display the name of table using the id of another table in Laravel I declare like this. But when I want to get the id to edit, the error is like the title. Please help me, I am very grateful.
Controller
public function manage_departments(){
$manage_departments=DB::table('departments')
->join('faculties','faculties.id','=','departments.faculty_id')
->orderBy('departments.created_at','desc')->get();
$all_manage_departments=view('admin.manage-departments')->with('manage_departments', $manage_departments);
return view('layouts.master')->with('admin.manage-departments', $all_manage_departments);
}
You don't have select in your query builder. As laravel doc said, you can specify what do you want to select in select method. I select faculties.id and departments.id for example.
DB::table('departments')
->select('faculties.id','departments.id')
->join('faculties','faculties.id','=','departments.faculty_id')
->orderBy('departments.created_at','desc')->get();

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

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)"} []

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