SQLSTATE[23000]:违反完整性约束:1052 列 'id' 在 where 子句中不明确
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous
当我在 Laravel 中使用另一个 table 的 ID 显示 table 的名称时,我这样声明。但是当我想获取id进行编辑的时候,报错就像标题一样。请帮助我,我非常感谢。
Controller
public 函数 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);
}
您的查询生成器中没有 select
。正如 laravel doc 所说,您可以在 select
方法中指定要 select 的内容。我以selectfaculties.id
和departments.id
为例。
DB::table('departments')
->select('faculties.id','departments.id')
->join('faculties','faculties.id','=','departments.faculty_id')
->orderBy('departments.created_at','desc')->get();
当我在 Laravel 中使用另一个 table 的 ID 显示 table 的名称时,我这样声明。但是当我想获取id进行编辑的时候,报错就像标题一样。请帮助我,我非常感谢。
Controller
public 函数 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);
}
您的查询生成器中没有 select
。正如 laravel doc 所说,您可以在 select
方法中指定要 select 的内容。我以selectfaculties.id
和departments.id
为例。
DB::table('departments')
->select('faculties.id','departments.id')
->join('faculties','faculties.id','=','departments.faculty_id')
->orderBy('departments.created_at','desc')->get();