CDbException

CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 1364 Field 'name' doesn't have a default value. The SQL statement executed was: INSERT INTO `gallery_photo` (`rank`, `gallery_id`, `file_name`) VALUES (:yp0, :yp1, :yp2)

D:\WebServer\Apache2.2\htdocs\yii\framework\db\CDbCommand.php(354)

342             return $n;
343         }
344         catch(Exception $e)
345         {
346             if($this->_connection->enableProfiling)
347                 Yii::endProfile('system.db.CDbCommand.execute('.$this->getText().$par.')','system.db.CDbCommand.execute');
348             $errorInfo = $e instanceof PDOException ? $e->errorInfo : null;
349             $message = $e->getMessage();
350             Yii::log(Yii::t('yii','CDbCommand::execute() failed: {error}. The SQL statement executed was: {sql}.',
351                 array('{error}'=>$message, '{sql}'=>$this->getText().$par)),CLogger::LEVEL_ERROR,'system.db.CDbCommand');
352             if(YII_DEBUG)
353                 $message .= '. The SQL statement executed was: '.$this->getText().$par;
354             throw new CDbException(Yii::t('yii','CDbCommand failed to execute the SQL statement: {error}',
355                 array('{error}'=>$message)),(int)$e->getCode(),$errorInfo);
356         }
357     }
358 
359     /**
360      * Executes the SQL statement and returns query result.
361      * This method is for executing an SQL query that returns result set.
362      * @param array $params input parameters (name=>value) for the SQL execution. This is an alternative
363      * to {@link bindParam} and {@link bindValue}. If you have multiple input parameters, passing
364      * them in this way can improve the performance. Note that if you pass parameters in this way,
365      * you cannot bind parameters or values using {@link bindParam} or {@link bindValue}, and vice versa.
366      * binding methods and  the input parameters this way can improve the performance.

Stack Trace

#2
+
 D:\WebServer\Apache2.2\htdocs\testapp\protected\extensions\galleryManager\models\GalleryPhoto.php(114): CActiveRecord->save(true, null)
109         ));
110     }
111 
112     public function save($runValidation = true, $attributes = null)
113     {
114         parent::save($runValidation, $attributes);
115         if ($this->rank == null) {
116             $this->rank = $this->id;
117             $this->setIsNewRecord(false);
118             $this->save(false);
119         }
#3
+
 D:\WebServer\Apache2.2\htdocs\testapp\protected\extensions\galleryManager\GalleryController.php(47): GalleryPhoto->save()
42             if (isset($_POST['GalleryPhoto']))
43                 $model->attributes = $_POST['GalleryPhoto'];
44 
45             $imageFile = CUploadedFile::getInstance($model, 'image');
46             $model->file_name = $imageFile->getName();
47             $model->save();
48 
49             $model->setImage($imageFile->getTempName());
50             header("Content-Type: application/json");
51             echo CJSON::encode(
52                 array(
#13
+
 D:\WebServer\Apache2.2\htdocs\testapp\index.php(13): CApplication->run()
08 defined('YII_DEBUG') or define('YII_DEBUG',true);
09 // specify how many levels of call stack should be shown in each log message
10 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
11 
12 require_once($yii);
13 Yii::createWebApplication($config)->run();
2012-10-22 17:14:03 Apache/2.2.21 (Win32) PHP/5.3.9 Yii Framework/1.1.12