I have a custom data table PA in the Craft database. I create a craft\db\ActiveRecord model and I want load() and save() data to it. The result will be custom GridView table with CRUD in front end combined with cms pages.

When I call $model->save() it throws Exception:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'dateUpdated' in 'field list'

The SQL being executed was: UPDATE `PA` SET `background`='#ffff00', `dateUpdated`='2018-10-03 11:50:26' 
WHERE `idPA`=17
Error Info: Array
[0] => 42S22
[1] => 1054
[2] => Unknown column 'dateUpdated' in 'field list'

Caused by: PDOException
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'dateUpdated' in 'field list'

What is the difference between craft\db\ActiveRecord and yii\db\ActiveRecord? Is there any recommendation how to use it?



The only difference between Craft and Yii active records are the columns dateCreated, dateUpdated and uid if you have these columns you should extend Crafts ActiveRecord since it's save function adds compability to those columns otherwise just use Yii2 ActiveRecord

  • The problem still consist if use yii\db\ActiveRecord; is extended Oct 7 '21 at 19:58
  • 1
    It became a little bit more difficult. It's easier to either include those columns or not use ActiveRecords. Otherwise you would need to inject a different yii/db/Command class to the existing yii/db/Schema/yii/db/Connection in order to use different Command class for your ActiveRecord. Oct 8 '21 at 6:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.