What does CDBException mean here and how do I resolve it?
<p>Please, I am totally new to Yii1.1, I am following a video tutorial and I have benn trying to follow up closely. I am trying to create and update the album model as indicated in the video tutorial. I typed everything the presenter typed: my codes are given below:</p>



<p>

<h1>The AlbumController</h1>

<p>class AlbumController extends Controller
{
    /**
     * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
     * using two-column layout. See 'protected/views/layouts/column2.php'.
     */
    public $layout='//layouts/column2';</p>

<pre><code>/**
 * @return array action filters
 */
public function filters()
{
    return array(
        'accessControl', // perform access control for CRUD operations
        'postOnly + delete', // we only allow deletion via POST request
    );
}

/**
 * Specifies the access control rules.
 * This method is used by the 'accessControl' filter.
 * @return array access control rules
 */
public function accessRules()
{
    return array(
        array('allow',  // allow all users to perform 'index' and 'view' actions
            'actions'=&gt;array('index','view'),
            'users'=&gt;array('*'),
        ),
        array('allow', // allow authenticated user to perform 'create' and 'update' actions
            'actions'=&gt;array('create','update'),
            'users'=&gt;array('@'),
        ),
        array('allow', // allow admin user to perform 'admin' and 'delete' actions
            'actions'=&gt;array('admin','delete'),
            'users'=&gt;array('admin'),
        ),
        array('deny',  // deny all users
            'users'=&gt;array('*'),
        ),
    );
}

/**
 * Displays a particular model.
 * @param integer $id the ID of the model to be displayed
 */
public function actionView($id)
{
    $this-&gt;render('view',array(
        'model'=&gt;$this-&gt;loadModel($id),
    ));
}

/**
 * Creates a new model.
 * If creation is successful, the browser will be redirected to the 'view' page.
 */
public function actionCreate()
{
    $model=new Album;

    // Uncomment the following line if AJAX validation is needed
     $this-&gt;performAjaxValidation($model);

    if(isset($_POST['Album']))
    {
        $model-&gt;attributes=$_POST['Album'];
        if($model-&gt;save()){
            //$this-&gt;redirect(array('view','id'=&gt;$model-&gt;id));
                            Yii::app()-&gt;user-&gt;setFlash('saved', 'Data saved!');
                            $this-&gt;redirect(array('update','id'=&gt;$model-&gt;id));
                    }
                            else{
                Yii::app()-&gt;user-&gt;setFlash('failure', 'Data not saved!');
            }


           }

    $this-&gt;render('create',array(
        'model'=&gt;$model,
    ));
}

/**
 * Updates a particular model.
 * If update is successful, the browser will be redirected to the 'view' page.
 * @param integer $id the ID of the model to be updated
 */
public function actionUpdate($id)
{
    $model=$this-&gt;loadModel($id);

    // Uncomment the following line if AJAX validation is needed
     $this-&gt;performAjaxValidation($model);

    if(isset($_POST['Album']))
    {
        $model-&gt;attributes=$_POST['Album'];
        if($model-&gt;save()){
            //$this-&gt;redirect(array('view','id'=&gt;$model-&gt;id));
                            Yii::app()-&gt;user-&gt;setFlash('saved', "Data saved!");
                            $this-&gt;redirect(array('update','id'=&gt;$model-&gt;id));
            }else{
                Yii::app()-&gt;user-&gt;setFlash('failure', "Data not saved!");
            }


}

      $this-&gt;render('update',array(
        'model'=&gt;$model,
    ));

/**
 * Deletes a particular model.
 * If deletion is successful, the browser will be redirected to the 'admin' page.
 * @param integer $id the ID of the model to be deleted
 */
    }
public function actionDelete($id)
{
    $this-&gt;loadModel($id)-&gt;delete();

    // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
    if(!isset($_GET['ajax']))
        $this-&gt;redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}

/**
 * Lists all models.
 */
public function actionIndex()
{
    $dataProvider=new CActiveDataProvider('Album');
    $this-&gt;render('index',array(
        'dataProvider'=&gt;$dataProvider,
    ));
}

/**
 * Manages all models.
 */
public function actionAdmin()
{
    $model=new Album('search');
    $model-&gt;unsetAttributes();  // clear any default values
    if(isset($_GET['Album']))
        $model-&gt;attributes=$_GET['Album'];

    $this-&gt;render('admin',array(
        'model'=&gt;$model,
    ));
}

/**
 * Returns the data model based on the primary key given in the GET variable.
 * If the data model is not found, an HTTP exception will be raised.
 * @param integer $id the ID of the model to be loaded
 * @return Album the loaded model
 * @throws CHttpException
 */
public function loadModel($id)
{
    $model=Album::model()-&gt;findByPk($id);
    if($model===null)
        throw new CHttpException(404,'The requested page does not exist.');
    return $model;
}

/**
 * Performs the AJAX validation.
 * @param Album $model the model to be validated
 */
protected function performAjaxValidation($model)
{
    if(isset($_POST['ajax']) &amp;&amp; $_POST['ajax']==='album-form')
    {
        echo CActiveForm::validate($model);
        Yii::app()-&gt;end();
    }
}
</code></pre>

<p>}</p>

<h1>The Album model class</h1>

<p>

<p>/**
 * This is the model class for table "tbl_album".
 *
 * The followings are the available columns in table 'tbl_album':
 * @property integer $id
 * @property string $name
 * @property string $tags
 * @property integer $owner_id
 * @property integer $shareable
 * @property string $created_dt
 *
 * The followings are the available model relations:
 * @property User $owner
 * @property Photo[] $photos
 */
class Album extends CActiveRecord
{
    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'tbl_album';
    }</p>

<pre><code>/**
 * @return array validation rules for model attributes.
 */
public function rules()
{
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
        array('owner_id, shareable, category_id', 'numerical', 'integerOnly'=&gt;true),
        array('name, tags', 'length', 'max'=&gt;255),
                    array('description', 'length', 'max'=&gt;1024),
                    array('description', 'match', 'pattern'=&gt;'/[\w]+/u'),// \-\_\'\ \,\p{L}0-!
        // The following rule is used by search().
        // @todo Please remove those attributes that should not be searched.
        array('id, name, tags, owner_id, shareable, created_dt', 'safe', 'on'=&gt;'search'),
    );
}

/**
 * @return array relational rules.
 */

    //defined function beforeSave()..

    protected function beforeSave(){
        if(parent::beforeSave()){
            if($this-&gt;isNewRecord){
                $this-&gt;created_dt = new CDbExpression("NOW()");
                $this-&gt;owner_id = Yii::app()-&gt;user-&gt;id;
            }
            return true;
        }else
            return false;

    }

    public function scopes(){
        return array(
            'shareable'=&gt;array(
                'order'=&gt;'created_dt DESC',
                'condition'=&gt;'shareable=1',
            )
    );
    }
public function relations()
{
    // NOTE: you may need to adjust the relation name and the related
    // class name for the relations automatically generated below.
    return array(
        'owner' =&gt; array(self::BELONGS_TO, 'User', 'owner_id'),
        'photos' =&gt; array(self::HAS_MANY, 'Photo', 'album_id'),
    );
}

/**
 * @return array customized attribute labels (name=&gt;label)
 */
public function attributeLabels()
{
    return array(
        'id' =&gt; 'ID',
        'name' =&gt; 'Name',
                    'tags' =&gt; 'Tags',
        'owner_id' =&gt; 'Owner',
                    'category_id'=&gt;'Category',
                    'description'=&gt;'Description',
                    'shareable' =&gt; 'Shareable',
        'created_dt' =&gt; 'Created Dt',
    );
}

/**
 * Retrieves a list of models based on the current search/filter conditions.
 *
 * Typical usecase:
 * - Initialize the model fields with values from filter form.
 * - Execute this method to get CActiveDataProvider instance which will filter
 * models according to data in model fields.
 * - Pass data provider to CGridView, CListView or any similar widget.
 *
 * @return CActiveDataProvider the data provider that can return the models
 * based on the search/filter conditions.
 */
public function search()
{
    // @todo Please modify the following code to remove attributes that should not be searched.

    $criteria=new CDbCriteria;
    $criteria-&gt;compare('name',$this-&gt;name,true);
    $criteria-&gt;compare('tags',$this-&gt;tags,true);
            $criteria-&gt;compare('description',$this-&gt;description);

    return new CActiveDataProvider($this, array(
        'criteria'=&gt;$criteria,
    ));
}

/**
 * Returns the static model of the specified AR class.
 * Please note that you should have this exact method in all your CActiveRecord descendants!
 * @param string $className active record class name.
 * @return Album the static model class
 */
public static function model($className=__CLASS__)
{
    return parent::model($className);
}
</code></pre>

<p>}</p>

<h1>The Photo Model Class</h1>

<p>

<p>/**
 * This is the model class for table "tbl_photo".
 *
 * The followings are the available columns in table 'tbl_photo':
 * @property integer $id
 * @property integer $album_id
 * @property string $filename
 * @property string $caption
 * @property string $alt_text
 * @property string $tags
 * @property integer $sort_order
 * @property string $created_dt
 * @property string $lastupdate_dt
 *
 * The followings are the available model relations:
 * @property Comment[] $comments
 * @property Album $album
 */</p>

<p>class Photo extends CActiveRecord
{<br>
     private $_uploads;</p>

<pre><code>/**
 * @return string the associated database table name
 */



public function tableName()
{
    return 'tbl_photo';
}

/**
 * @return array validation rules for model attributes.
 */
public function rules()
{
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
        array('album_id, sort_order', 'numerical', 'integerOnly'=&gt;true),
        array('filename', 'length', 'max'=&gt;500),
        array('tags', 'length', 'max'=&gt;256),
        array('caption, alt_text, created_dt, lastupdate_dt', 'safe'),
        // The following rule is used by search().
        // @todo Please remove those attributes that should not be searched.
        array('id, album_id, filename, caption, alt_text, tags, sort_order, created_dt, lastupdate_dt', 'safe', 'on'=&gt;'search'),
    );
}

/**
 * @return array relational rules.
 */
public function relations()
{
    // NOTE: you may need to adjust the relation name and the related
    // class name for the relations automatically generated below.
    return array(
        'comments' =&gt; array(self::HAS_MANY, 'Comment', 'photo_id'),
        'album' =&gt; array(self::BELONGS_TO, 'Album', 'album_id'),
    );
}

/**
 * @return array customized attribute labels (name=&gt;label)
 */
public function attributeLabels()
{
    return array(
        'id' =&gt; 'ID',
        'album_id' =&gt; 'Album',
        'filename' =&gt; 'Filename',
        'caption' =&gt; 'Caption',
        'alt_text' =&gt; 'Alt Text',
        'tags' =&gt; 'Tags',
        'sort_order' =&gt; 'Sort Order',
        'created_dt' =&gt; 'Created Dt',
        'lastupdate_dt' =&gt; 'Lastupdate Dt',
    );
}

    public function getImageParam(){
     if(empty($this-&gt;_uploads)){
         $this-&gt;_uploads = Yii::app()-&gt;params['uploads']. "/";
         return $this-&gt;_uploads;
     }
 }
    public function getUrl(){
    return $this-&gt;getImageParam()."uploads/".CHtml::encode($this-&gt;filename); 
 }

 public function getThumb(){
     return $this-&gt;getImageParam()."thumbs/".CHtml::encode($this-&gt;filename);
 }


/**
 * Retrieves a list of models based on the current search/filter conditions.
 *
 * Typical usecase:
 * - Initialize the model fields with values from filter form.
 * - Execute this method to get CActiveDataProvider instance which will filter
 * models according to data in model fields.
 * - Pass data provider to CGridView, CListView or any similar widget.
 *
 * @return CActiveDataProvider the data provider that can return the models
 * based on the search/filter conditions.
 */
public function search()
{
    // @todo Please modify the following code to remove attributes that should not be searched.

    $criteria=new CDbCriteria;

    $criteria-&gt;compare('id',$this-&gt;id);
    $criteria-&gt;compare('album_id',$this-&gt;album_id);
    $criteria-&gt;compare('filename',$this-&gt;filename,true);
    $criteria-&gt;compare('caption',$this-&gt;caption,true);
    $criteria-&gt;compare('alt_text',$this-&gt;alt_text,true);
    $criteria-&gt;compare('tags',$this-&gt;tags,true);
    $criteria-&gt;compare('sort_order',$this-&gt;sort_order);
    $criteria-&gt;compare('created_dt',$this-&gt;created_dt,true);
    $criteria-&gt;compare('lastupdate_dt',$this-&gt;lastupdate_dt,true);

    return new CActiveDataProvider($this, array(
        'criteria'=&gt;$criteria,
    ));
}

/**
 * Returns the static model of the specified AR class.
 * Please note that you should have this exact method in all your CActiveRecord descendants!
 * @param string $className active record class name.
 * @return Photo the static model class
 */
public static function model($className=__CLASS__)
{
    return parent::model($className);
}
</code></pre>

<p>}</p>

<h1>The Photo Model</h1>

<p>

<p>/**
 * This is the model class for table "tbl_photo".
 *
 * The followings are the available columns in table 'tbl_photo':
 * @property integer $id
 * @property integer $album_id
 * @property string $filename
 * @property string $caption
 * @property string $alt_text
 * @property string $tags
 * @property integer $sort_order
 * @property string $created_dt
 * @property string $lastupdate_dt
 *
 * The followings are the available model relations:
 * @property Comment[] $comments
 * @property Album $album
 */</p>

<p>class Photo extends CActiveRecord
{<br>
     private $_uploads;</p>

<pre><code>/**
 * @return string the associated database table name
 */



public function tableName()
{
    return 'tbl_photo';
}

/**
 * @return array validation rules for model attributes.
 */
public function rules()
{
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
        array('album_id, sort_order', 'numerical', 'integerOnly'=&gt;true),
        array('filename', 'length', 'max'=&gt;500),
        array('tags', 'length', 'max'=&gt;256),
        array('caption, alt_text, created_dt, lastupdate_dt', 'safe'),
        // The following rule is used by search().
        // @todo Please remove those attributes that should not be searched.
        array('id, album_id, filename, caption, alt_text, tags, sort_order, created_dt, lastupdate_dt', 'safe', 'on'=&gt;'search'),
    );
}

/**
 * @return array relational rules.
 */
public function relations()
{
    // NOTE: you may need to adjust the relation name and the related
    // class name for the relations automatically generated below.
    return array(
        'comments' =&gt; array(self::HAS_MANY, 'Comment', 'photo_id'),
        'album' =&gt; array(self::BELONGS_TO, 'Album', 'album_id'),
    );
}

/**
 * @return array customized attribute labels (name=&gt;label)
 */
public function attributeLabels()
{
    return array(
        'id' =&gt; 'ID',
        'album_id' =&gt; 'Album',
        'filename' =&gt; 'Filename',
        'caption' =&gt; 'Caption',
        'alt_text' =&gt; 'Alt Text',
        'tags' =&gt; 'Tags',
        'sort_order' =&gt; 'Sort Order',
        'created_dt' =&gt; 'Created Dt',
        'lastupdate_dt' =&gt; 'Lastupdate Dt',
    );
}

    public function getImageParam(){
     if(empty($this-&gt;_uploads)){
         $this-&gt;_uploads = Yii::app()-&gt;params['uploads']. "/";
         return $this-&gt;_uploads;
     }
 }
    public function getUrl(){
    return $this-&gt;getImageParam()."uploads/".CHtml::encode($this-&gt;filename); 
 }

 public function getThumb(){
     return $this-&gt;getImageParam()."thumbs/".CHtml::encode($this-&gt;filename);
 }


/**
 * Retrieves a list of models based on the current search/filter conditions.
 *
 * Typical usecase:
 * - Initialize the model fields with values from filter form.
 * - Execute this method to get CActiveDataProvider instance which will filter
 * models according to data in model fields.
 * - Pass data provider to CGridView, CListView or any similar widget.
 *
 * @return CActiveDataProvider the data provider that can return the models
 * based on the search/filter conditions.
 */
public function search()
{
    // @todo Please modify the following code to remove attributes that should not be searched.

    $criteria=new CDbCriteria;

    $criteria-&gt;compare('id',$this-&gt;id);
    $criteria-&gt;compare('album_id',$this-&gt;album_id);
    $criteria-&gt;compare('filename',$this-&gt;filename,true);
    $criteria-&gt;compare('caption',$this-&gt;caption,true);
    $criteria-&gt;compare('alt_text',$this-&gt;alt_text,true);
    $criteria-&gt;compare('tags',$this-&gt;tags,true);
    $criteria-&gt;compare('sort_order',$this-&gt;sort_order);
    $criteria-&gt;compare('created_dt',$this-&gt;created_dt,true);
    $criteria-&gt;compare('lastupdate_dt',$this-&gt;lastupdate_dt,true);

    return new CActiveDataProvider($this, array(
        'criteria'=&gt;$criteria,
    ));
}

/**
 * Returns the static model of the specified AR class.
 * Please note that you should have this exact method in all your CActiveRecord descendants!
 * @param string $className active record class name.
 * @return Photo the static model class
 */
public static function model($className=__CLASS__)
{
    return parent::model($className);
}
</code></pre>

<p>}</p>

<p>I am getting this error: <code>CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (</code>school2go2<code>.</code>tbl_album<code>, CONSTRAINT</code>tbl_album_ibfk_1<code>FOREIGN KEY (</code>owner_id<code>) REFERENCES</code>tbl_user<code>(</code>id<code>) ON DELETE NO ACTION ON UPDATE NO ACTION). The SQL statement executed was: INSERT INTO</code>tbl_album<code>(</code>name<code>,</code>tags<code>,</code>description<code>,</code>shareable<code>,</code>created_dt<code>,</code>owner_id<code>) VALUES (:yp0, :yp1, :yp2, :yp3, NOW(), :yp4)</code></p>

<p>Please I am totally new to yii and even StackOverflow, pardon my inappropriate editing.I am still learning.</p>