Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ramonnogueira's avatar

Column not found but it's not in query....

I'm getting this error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'accounts_id' in 'NEW' (SQL: update users_act set stopped = 1, users_act.updated_at = 2020-10-15 14:06:48 where id = 3184);

THE PROBLEM: Column 'accounts_id' is not in query and the updated_at value is not quoted

This happens when I try to save an ORM.

Trace: #0 C:\localhost\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php(143): Doctrine\DBAL\Driver\PDO\Exception::new(Object(PDOException)) #1 C:\localhost\vendor\illuminate\database\Connection.php(495): Doctrine\DBAL\Driver\PDOStatement->execute() #2 C:\localhost\vendor\illuminate\database\Connection.php(672): Illuminate\Database\Connection->Illuminate\Database{closure}('update act_fol...', Array) #3 C:\localhost\vendor\illuminate\database\Connection.php(639): Illuminate\Database\Connection->runQueryCallback('update act_fol...', Array, Object(Closure)) #4 C:\localhost\vendor\illuminate\database\Connection.php(504): Illuminate\Database\Connection->run('update act_fol...', Array, Object(Closure)) #5 C:\localhost\vendor\illuminate\database\Connection.php(429): Illuminate\Database\Connection->affectingStatement('update act_fol...', Array) #6 C:\localhost\vendor\illuminate\database\Query\Builder.php(2902): Illuminate\Database\Connection->update('update `act_fol...', Array) #7 C:\localhost\vendor\illuminate\database\Eloquent\Builder.php(800): Illuminate\Database\Query\Builder->update(Array) #8 C:\localhost\vendor\illuminate\database\Eloquent\Model.php(798): Illuminate\Database\Eloquent\Builder->update(Array) #9 C:\localhost\vendor\illuminate\database\Eloquent\Model.php(713): Illuminate\Database\Eloquent\Model->performUpdate(Object(Illuminate\Database\Eloquent\Builder)) #10 C:\localhost\domain\Tasks\Tipos\TaskUnfollow.php(38): Illuminate\Database\Eloquent\Model->save()

0 likes
6 replies
ramonnogueira's avatar

$acts = App\Models\UsersAct::where('stopped', 0)->get(); foreach ($acts as $act) { $acts->stopped = 1; $acts->save(); }

previously, in another module, there was a queue that requested data in another table using the "accounts_id" column, in a relationship.

Sinnbeck's avatar

And the UsersAct model? What is the table called?

ramonnogueira's avatar

// table users_act in BaseUsersAct class UsersAct extends BaseUsersAct {

use BitBooleans;

protected $casts = [
    'stopped' => 'boolean',
    'playing' => 'boolean',
	...
	...
];

protected $fillable = [
	'stopped',
	'playing',
	...
	...
];

}

Previously:

// table config_opts in BaseConfigOpts class ConfigOpts extends BaseConfigOpts {

protected $casts = [
	"by_email" => 'boolean',
	...
	...
];

protected $fillable = [
	"accounts_id",
	"by_email",
	...
	...
];

public function getConfig()
{
    return $this->hasMany(Accounts::class, "accounts_id", "id");
}

}

// i was called like: ConfigOpts::where('by_email', 1)->getConfig()->all();

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Set timestamps to false

public $timestamps = false;
ramonnogueira's avatar

Solved! The problem was a trigger in mysql that used to call accounts_id in Insert queries.

Thank you for the promptness!

Please or to participate in this conversation.