tracker: Column not found: 1054 Unknown column 'user_agent' in 'field list' ...

I got this error:

Illuminate\Database\QueryException SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user_agent' in 'field list' (SQL: update tracker_sessionssetuser_agent= Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0,updated_at= 2017-09-23 06:40:46 whereid= 301550)

But even on a fresh install I don’t have this column in the tracker_sessions table! Is there a migration missing or something like that?

thanks

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 7
  • Comments: 26 (3 by maintainers)

Commits related to this issue

Most upvoted comments

same issue here. Followed instructions as per readme.

edit:

I created this migration to deal with this issue

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class TrackerUserAgentFieldToTrackerSessions extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //
        Schema::connection('tracker')->table('tracker_sessions', function (Blueprint $table) {
            $table->string('user_agent')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::connection('tracker')->table('tracker_sessions', function (Blueprint $table) {
            $table->dropColumn(['user_agent']);
        });
    }
}

Hello,

I resolved temporarily:

In the ensureSessionDataIsComplete() function of the file “pragmarx/tracker/src/Data/Repositories/Session.php” +or- in line 135, I added this:

if($key === 'user_agent') continue;

I also have same problem. 😄

I FIXED this by overriding the class that has the issue with composer:

First, copy the original class from the vendor to your app: $ cp vendor/pragmarx/tracker/src/Data/Repositories/Session.php app/VendorOverrides/PragmaRX/Tracker/Data/Repositories/Session.php

Second, add the following inside the autoload object in composer.json: "files": ["app/VendorOverrides/PragmaRX/Tracker/Data/Repositories/Session.php"]

Your composer.json’s autoload should be like so:

"autoload": {
    "psr-4": {
        "App\\": "app/"
    },
    "classmap": [
        "database/seeds",
        "database/factories"
    ],
    "files": ["app/VendorOverrides/PragmaRX/Tracker/Data/Repositories/Session.php"]
},

Third, add the following line after line 134 of app/VendorOverrides/PragmaRX/Tracker/Data/Repositories/Session.php: if ($key === 'user_agent') continue;

The ensureSessionDataIsComplete() function in our Session.php should now be:

private function ensureSessionDataIsComplete()
{
    $sessionData = $this->getSessionData();
    $wasComplete = true;
    foreach ($this->sessionInfo as $key => $value) {
        if ($key === 'user_agent') continue; // <--- THIS IS WHAT IS NEW!!!
        if ($sessionData[$key] !== $value) {
            if (!isset($model)) {
                $model = $this->find($this->sessionInfo['id']);
            }
            $model->setAttribute($key, $value);
            $model->save();
            $wasComplete = false;
        }
    }
    if (!$wasComplete) {
        $this->storeSession();
    }
}

Finally, run $ composer dump-autoload.

Pull-requests for this like #391 or #448 are not yet merged. Until that, this should fix this issue.

I observed the same behavior in one of my apps while changing from desktop to mobile view in chromium and then reloading the page. The point is that the key ‘user_agent’ is built in vendor/pragmarx/tracker/src/Tracker.php in makeSessionData() and then later in vendor/pragmarx/tracker/src/Data/Repositories/Session.php in ensureSessionDataIsComplete() it wants to be stored back as an attribute of tracker_session.

The simplest workaround might be maikos code trick from September 2017 by just ignoring this field in the update loop. But there should also exist a cleaner way. Maybe @antonioribeiro has an idea?

Got this error as well. Wondering if adding the column would be the right solution as there is already an agent_id in the table. Shouldn’t it be stored in the tracker_agents instead?

+1 I also have the same problem…