简体   繁体   English

如何解决完整性约束违规:1052 where子句中的'agent_id'列不明确

[英]How to solve Integrity constraint violation: 1052 Column 'agent_id' in where clause is ambiguous

Integrity constraint violation: 1052 Column 'agent_id' in where clause is ambiguous 完整性约束违规:1052 where子句中的'agent_id'列不明确

I have try but still can't find the error of this datatables 我试过但仍然找不到这个数据表的错误

public function customerOrderList(Request $request, $agent_id){
    $customer_orders = CustomerOrder::join('agent as a', 'a.agent_id','=','customer_order.agent_id')
    ->select('customer_order.*', 'a.name as agent_name')
    ->where('agent_id', $agent_id)
    ->get();

    $datatables = DataTables::of($customer_orders)
    ->addColumn('actions', function($customer_order){
      $html ='';
      $view = route('customer-order.invoice', $customer_order->doc_id);
      $html .= "<a class='btn btn-primary btn-sm' href='$view'><i class='far fa-fw fa-eye'></i></a>";

      return $html;
    })
    ->rawColumns(['actions']);

    return $datatables->make(true);
  }

-show datatable - 显示数据表

It means that multiple tables in your query have the same agent_id column, and your query cannot determine which one to use. 这意味着查询中的多个表具有相同的agent_id列,并且您的查询无法确定要使用哪个表。 You've used 'customer_order.agent_id' in one clause, but only 'agent_id' in the another. 您在一个子句中使用了'customer_order.agent_id' ,但在另一个子句中只使用了'agent_id'

When using ->join() , it's sometimes required to be as specific as possible with your references (depends on your table structure/columns being selected, etc): 使用->join() ,有时需要使用引用尽可能具体(取决于您选择的表结构/列等):

$customer_orders = CustomerOrder::join('agent as a', 'a.agent_id','=','customer_order.agent_id')
  ->select('customer_order.*', 'a.name as agent_name')
  ->where('customer_order.agent_id', $agent_id) // Here, add table name before `agent_id`, likely `customer_order`
  ->get();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决完整性约束违规:1052 列 &#39;id&#39; in where 子句在 laravel 中不明确 - How to solve Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous in laravel Laravel 完整性约束违规:1052 列 'id' in where 子句不明确 - Laravel Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous 违反完整性约束:1052列和where子句不明确 - Integrity constraint violation: 1052 Column and in where clause is ambiguous 违反完整性约束:1052 where子句不明确的列&#39;prof_id&#39;Laravel - Integrity constraint violation: 1052 Column 'prof_id' in where clause is ambiguous Laravel Laravel Eloquent:违反完整性约束:where 子句中的 1052 列“id”不明确 - Laravel Eloquent: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous SQLSTATE [23000]:违反完整性约束:1052 where 子句中的列 'id' 不明确 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous Laravel 6 错误:SQLSTATE[23000]:违反完整性约束:1052 where 子句中的列“id_perusahaan”不明确 - Laravel 6 Error : SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id_perusahaan' in where clause is ambiguous Laravel SQL 错误:违反完整性约束:1052 where 子句中的列“id”不明确 - Laravel SQL Error: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous 完整性约束违规:laravel 中 where 子句中的 1052 列“created_at”不明确 - Integrity constraint violation: 1052 Column 'created_at' in where clause is ambiguous in laravel SQLSTATE [23000]:违反完整性约束:1052 where 子句中的列“值”不明确 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'value' in where clause is ambiguous
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM