Php Laravel雄辩的SQLSTATE[23000]:完整性约束冲突:1052列。。。where子句中的where子句是不明确的
我得到这个错误“完整性约束冲突:where子句中1052列'disabled_at'不明确” 虽然在我的where中,我在列之前添加了表名,并且在join语句中也添加了表名,但它仍然给了我上面的错误。 以下是代码snipet:Php Laravel雄辩的SQLSTATE[23000]:完整性约束冲突:1052列。。。where子句中的where子句是不明确的,php,mysql,laravel,eloquent,Php,Mysql,Laravel,Eloquent,我得到这个错误“完整性约束冲突:where子句中1052列'disabled_at'不明确” 虽然在我的where中,我在列之前添加了表名,并且在join语句中也添加了表名,但它仍然给了我上面的错误。 以下是代码snipet: $name = ($params['query']) ? $params['query'] : ''; $perPage = (isset($params['perpage']) && $params['perpage']
$name = ($params['query']) ? $params['query'] : '';
$perPage = (isset($params['perpage']) && $params['perpage'] !== null) ?
intval($params['perpage']) : 50;
$query = $this->with('sections');
// search disabled users
if ($disabled) {
$query->withTrashed();
// if not all, limit to disabled only
if (!$allUsers) {
$query->whereNotNull('users.disabled_at');
}
}
// exclude name search when blank to increase query speed
if ($name !== '') {
$query->join('sections', 'users.section_id', '=', 'sections.id');
$query->where(DB::raw("CONCAT(users.title,' ',users.first_name,' ',users.last_name,' ',users.email,' ',sections.name)"), 'like', '%' . $name . '%');
}
任何帮助都将不胜感激。好的,谢谢大家的建议。
通过使用您的建议查看原始mysql查询,并使用
DB::enableQueryLog()
和query->toSQL()
输出,我发现了问题所在,后者实际上对我有效。基本上,disabled_at
列与soft delete'deleted_at'
一样工作,因此它要么为NULL,要么有时间戳,因此,默认情况下,原始查询有一个“…where.”disabled_at“为NULL…”(我不知道),并且因为sections表也有一个“disabled_at”列,它不知道这两个表disabled\u at
属于哪一个,因此我必须使用以下查询指定表“whereNULL('users.disabled\u at')
..”,而不仅仅是让默认值运行。好的,谢谢大家的建议。
通过使用您的建议查看原始mysql查询,并使用
DB::enableQueryLog()
和query->toSQL()
输出,我发现了问题所在,后者实际上对我有效。基本上,disabled_at
列与soft delete'deleted_at'
一样工作,因此它要么为NULL,要么有时间戳,因此,默认情况下,原始查询有一个“…where.”disabled_at“为NULL…”(我不知道),并且因为sections表也有一个“disabled_at”列,它不知道这两个表disabled_at
属于哪一个表,因此我必须使用以下查询指定表“whereNULL('users.disabled_at')
..”,而不仅仅让默认值运行。在查询之前使用DB::enableQueryLog()显示查询,并使用dd(DB::getQueryLog()获得结果;您将了解查询中“disabled_at”列的使用位置。您可以执行dd($query->toSQL())
并在此处共享结果吗?(或者检查它,看看是否有任何明显的问题可以自己解决)错误消息表明,有多个列的同一列名被禁用。(表1.at和表2.at)。现在,您的数据库不知道您所指的是哪个已禁用的\u。您确定错误发生在这里吗?在查询之前使用DB::enableQueryLog()显示查询,并使用dd(DB::getQueryLog())获取结果;您将了解查询中“disabled_at”列的使用位置。您可以执行dd($query->toSQL())
并在此处共享结果吗?(或者检查它,看看是否有任何明显的问题可以自己解决)错误消息表明,有多个列的同一列名被禁用。(表1.at和表2.at)。现在,您的数据库不知道您所指的是哪个已禁用的\u。你确定错误发生在这里吗?