Laravel 7 MySQL 违反完整性约束
Laravel 7 MySQL integrity constraint violation
我正在尝试创建一个页面,点击特定用户将从两个不同的 MySQL table 中获取关于他们的所有信息。两个 table 的每一行共有的公共列是用户 table 中的 id 列(匹配 client_profiles
table 中的 userid
列).
控制器
class ClientController extends Controller
{
public function viewclient($id)
{
$client = DB::table('users')
->join('client_profiles', 'users.id', 'client_profiles.userid')
->having('id', '>', $id)
->get();
return view('viewclient', compact('client'));
}
}
错误
Integrity constraint violation: 1052 Column 'id' in having clause is
ambiguous (SQL: select * from users
inner join client_profiles
on
users
.id
= client_profiles
.userid
having id
> 2)
在我的 Blade 文件中我有...
<input id="grid-first-name" type="text" value='{{ $client->userid }}'>
您确定是 id > 2 而不是 id = 2 吗? id 不明确,所以你必须点它
->having('users.id', '>', $id)
我正在尝试创建一个页面,点击特定用户将从两个不同的 MySQL table 中获取关于他们的所有信息。两个 table 的每一行共有的公共列是用户 table 中的 id 列(匹配 client_profiles
table 中的 userid
列).
控制器
class ClientController extends Controller
{
public function viewclient($id)
{
$client = DB::table('users')
->join('client_profiles', 'users.id', 'client_profiles.userid')
->having('id', '>', $id)
->get();
return view('viewclient', compact('client'));
}
}
错误
Integrity constraint violation: 1052 Column 'id' in having clause is ambiguous (SQL: select * from
users
inner joinclient_profiles
onusers
.id
=client_profiles
.userid
havingid
> 2)
在我的 Blade 文件中我有...
<input id="grid-first-name" type="text" value='{{ $client->userid }}'>
您确定是 id > 2 而不是 id = 2 吗? id 不明确,所以你必须点它
->having('users.id', '>', $id)