Error from Command.php in my logs

Hi I’m using Yii and I’m logging errors to track them but I got an error from Command.php I can’t resolve.

Here is the stacktrace :

I can’t understand where the ‘message.id’ comes from.

If you need any further informations on functions/code just let me know. I got a bit lost by this stack trace. Not sure where to look exactly.

Thank you in advance.

PS: here is the text of the stacktrace

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'message.id' in 'where clause' in /xxxx/application/vendor/yiisoft/yii2/db/Command.php:1293
Stack trace:
#0 /xxxx/application/vendor/yiisoft/yii2/db/Command.php(1293): PDOStatement->execute()
#1 /xxxx/application/vendor/yiisoft/yii2/db/Command.php(1159): yii\db\Command->internalExecute('SELECT `m`.* FR...')
#2 /xxxx/application/vendor/yiisoft/yii2/db/Command.php(415): yii\db\Command->queryInternal('fetch', NULL)
#3 /xxxx/application/vendor/yiisoft/yii2/db/Query.php(285): yii\db\Command->queryOne()
#4 /xxxx/application/vendor/yiisoft/yii2/db/ActiveQuery.php(304): yii\db\Query->one(NULL)
#5 /xxxx/application/models/query/MessageQuery.php(46): yii\db\ActiveQuery->one(NULL)
#6 /xxxx/application/behaviors/PolymorphicRelation.php(58): app\models\query\MessageQuery->one()
#7 [internal function]: app\behaviors\PolymorphicRelation->getPolymorphicRelation()
#8 /xxxx/application/vendor/yiisoft/yii2/base/Component.php(297): call_user_func_array(Array, Array)
#9 /xxxx/application/models/Notification.php(113): yii\base\Component->__call('getPolymorphicR...', Array)
#10 /xxxx/content/themes/atpk/widgets/views/notifications/header.php(64): app\models\Notification->getBaseModel()
#11 /xxxx/application/vendor/yiisoft/yii2/base/View.php(348): require('/xxxx/...')
#12 /xxxx/application/vendor/yiisoft/yii2/base/View.php(257): yii\base\View->renderPhpFile('/xxxx/...', Array)
#13 /xxxx/application/base/View.php(95): yii\base\View->renderFile('/xxxx/...', Array, Object(atpk\widgets\Notifications))
#14 /xxxx/application/vendor/yiisoft/yii2/base/View.php(156): app\base\View->renderFile('/xxxx/...', Array, Object(atpk\widgets\Notifications))
#15 /xxxx/application/vendor/yiisoft/yii2/base/Widget.php(236): yii\base\View->render('notifications/h...', Array, Object(atpk\widgets\Notifications))
#16 /xxxx/content/themes/atpk/widgets/Notifications.php(29): yii\base\Widget->render('notifications/h...', Array)
#17 /xxxx/application/vendor/yiisoft/yii2/base/Widget.php(140): atpk\widgets\Notifications->run()
#18 /xxxx/content/themes/atpk2/views/partials/header.php(25): yii\base\Widget::widget()
#19 /xxxx/application/vendor/yiisoft/yii2/base/View.php(348): require('/xxxx/...')
#20 /xxxx/application/vendor/yiisoft/yii2/base/View.php(257): yii\base\View->renderPhpFile('/xxxx/...', Array)
#21 /xxxx/application/base/View.php(99): yii\base\View->renderFile('/xxxx/...', Array, NULL)
#22 /xxxx/application/vendor/yiisoft/yii2/base/View.php(156): app\base\View->renderFile('/xxxx/...', Array, NULL)
#23 /xxxx/content/themes/atpk2/views/layouts/page-profile.php(9): yii\base\View->render('//partials/head...')
#24 /xxxx/application/vendor/yiisoft/yii2/base/View.php(348): require('/xxxx/...')
#25 /xxxx/application/vendor/yiisoft/yii2/base/View.php(257): yii\base\View->renderPhpFile('/xxxx/...', Array)
#26 /xxxx/application/base/View.php(99): yii\base\View->renderFile('/xxxx/...', Array, Object(app\controllers\ProfileController))
#27 /xxxx/application/vendor/yiisoft/yii2/base/Controller.php(424): app\base\View->renderFile('/xxxx/...', Array, Object(app\controllers\ProfileController))
#28 /xxxx/application/vendor/yiisoft/yii2/base/Controller.php(410): yii\base\Controller->renderContent('\n...')
#29 /xxxx/application/base/Controller.php(107): yii\base\Controller->render('view', Array)
#30 /xxxx/application/controllers/ProfileController.php(148): app\base\Controller->render('view', Array)
#31 [internal function]: app\controllers\ProfileController->actionView('clarika')
#32 /xxxx/application/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#33 /xxxx/application/vendor/yiisoft/yii2/base/Controller.php(180): yii\base\InlineAction->runWithParams(Array)
#34 /xxxx/application/vendor/yiisoft/yii2/base/Module.php(528): yii\base\Controller->runAction('view', Array)
#35 /xxxx/application/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction('profile/view', Array)
#36 /xxxx/application/vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#37 /xxxx/index.php(24): yii\base\Application->run()
#38 {main}
Additional Information:
Array
(
[0] => 42S22
[1] => 1054
[2] => Unknown column 'message.id' in 'where clause'
)

Hi TitoDev, the error is with your SQL command:

Seems that you are using an alias m to your message table, but you are using the message keyword to reference to this table inside your WHERE clause.

Just change where it says message.id to m.id or remove the alias from the table.