Answers.Body: <p>The only difference between Craft and Yii active records are the columns <code>dateCreated</code>, <code>dateUpdated</code> and <code>uid</code> if you have these columns you should extend Crafts <code>ActiveRecord</code> since it's <code>save</code> function adds compability to those columns otherwise  just use Yii2 <code>ActiveRecord</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-10-07T19:58:53.647Z
Answers.Text: The problem still consist if use yii\db\ActiveRecord; is extended
Answers.UserDisplayName: Honsa Stunna
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-10-08T06:59:17.760Z
Answers.Text: 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.
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-03T12:42:21.710Z
Answers.LastActivityDate: 2018-10-03T12:42:21.710Z
Answers.UserDisplayName: Robin Schambach
Body: <p>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.</p>
  
  <p>When I call $model->save() it throws Exception:</p>
  
  <pre><code>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] =&gt; 42S22
  [1] =&gt; 1054
  [2] =&gt; Unknown column 'dateUpdated' in 'field list'
  )
  
  Caused by: PDOException
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'dateUpdated' in 'field list'
  </code></pre>
  
  <p>What is the difference between craft\db\ActiveRecord and yii\db\ActiveRecord? Is there any recommendation how to use it?</p>
  
  <p>Thanks.</p>
  
Tags: <plugin-development><database>
Title: Does Craft ActiveRecord require any special table column (dateUpdated, dateCreated,...)?
ThreadText: # Does Craft ActiveRecord require any special table column (dateUpdated, dateCreated,...)?
  
  (Asked by: username_0 on 2018-10-03)
  
  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?
  
  Thanks.
  
  **Tags:** plugin-development, database
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-10-03. Score: 4 | Accepted answer
  
  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`
  
  > **Comments:**
  > **username_2**: The problem still consist if use yii\db\ActiveRecord; is extended  
  > **username_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.  
  
  ---
  
  