Php SQLSTATE[42S22]:未找到列:1054未知列(似乎试图使用ID作为列名)

Php SQLSTATE[42S22]:未找到列:1054未知列(似乎试图使用ID作为列名),php,mysql,laravel,eloquent,query-builder,Php,Mysql,Laravel,Eloquent,Query Builder,因此,我最近一直在与Laravel的示波器进行斗争,我发现以下错误: SQLSTATE[42S22]:未找到列:1054未知列 on子句“SQL:选择配置文件”中的“visitors.visitorable_id”, profile\u genres.genre\u id作为pivot\u genre\u id, profile\u genres.profile\u id作为profiles中的pivot\u profile\u id profiles.id上的内部连接配置文件\u类型= pro

因此,我最近一直在与Laravel的示波器进行斗争,我发现以下错误:

SQLSTATE[42S22]:未找到列:1054未知列 on子句“SQL:选择配置文件”中的“visitors.visitorable_id”, profile\u genres.genre\u id作为pivot\u genre\u id, profile\u genres.profile\u id作为profiles中的pivot\u profile\u id profiles.id上的内部连接配置文件\u类型= profile\u genres.profile\u id左加入选择COUNTid访问, 访客组中的ip地址、可访问id、可访问类型 访客上出现的ip\u地址。可访问\u id= db885a18-f0b7-4f55-9d93-743fbb5d9c94和 visitors.visitorable_type=App\Profile其中 profile_genres.genre_id=038ba398-8998-4cd6-950c-60b4a6c401cc和 profiles.deleted_at为空

以下是导致此错误的查询:

public function scopePopular($query, $limit = 10)
    {
        $query->leftJoin(DB::raw('(SELECT COUNT(id) visits, ip_address, visitorable_id, visitorable_type FROM `visitors` GROUP BY ip_address) occurences'), function($join)
        {
            $join->on('visitors.visitorable_id', '=', 'db885a18-f0b7-4f55-9d93-743fbb5d9c94');
            $join->where('visitors.visitorable_type', '=', 'App\Profile');
        });
        return $query;
    }
编辑 根据要求,我的访客表迁移:

public function up()
    {
        Schema::create('visitors', function(Blueprint $table) {
            $table->increments('id');

            $table->uuid('visitorable_id');
            $table->string('visitorable_type');

            $table->string('isp')->nullable();
            $table->string('country_code')->nullable();
            $table->string('country')->nullable();
            $table->string('city')->nullable();
            $table->string('region')->nullable();
            $table->string('region_name')->nullable();
            $table->string('ip_address')->nullable();
            $table->string('timezone')->nullable();
            $table->string('zip_code')->nullable();
            $table->string('latitude')->nullable();
            $table->string('longitude')->nullable();

            $table->timestamps();
        });
    }
基本上,您对访问者执行select语句,但调用select语句的响应会发生。因此,temp表中不存在visitors.visitorable\u id,但是occurrences.visitorable\u id应该存在。

因此,子查询中没有visitors表,将visitors.visitorable\u id更改为occurrences.visitorable\u id就成功了

$query->leftJoin(DB::raw('(SELECT COUNT(id) visits, ip_address, visitorable_id, visitorable_type FROM `visitors` GROUP BY ip_address) occurences'), function($join)
{
    $join->on('occurences.visitorable_id', '=', 'profiles.id');
    $join->where('occurences.visitorable_type', '=', 'App\Profile');
});

未知列“访问者.可访问\u id”。表上是否存在可访问的\u id?是否可以发布访问者表的架构?我想你在我的移民问题上指的是错误的
$query->leftJoin(DB::raw('(SELECT COUNT(id) visits, ip_address, visitorable_id, visitorable_type FROM `visitors` GROUP BY ip_address) occurences'), function($join)
{
    $join->on('occurences.visitorable_id', '=', 'profiles.id');
    $join->where('occurences.visitorable_type', '=', 'App\Profile');
});