CActiveRecord::save() problem

Hi. I had an “Edit My Info” page set up for users. It was working nicely. I moved on to work on other parts of the site. I came back to “Edit My Info”, and now when I do CActiveRecord::save(), I get this error (‘id’ is the auto increment primary key!):



CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value

Source File


00244:             if($this->_connection->enableProfiling)

00245:                 Yii::endProfile('system.db.CDbCommand.execute('.$this->getText().')','system.db.CDbCommand.execute');


00247:             return $n;

00248:         }

00249:         catch(Exception $e)

00250:         {

00251:             if($this->_connection->enableProfiling)

00252:                 Yii::endProfile('system.db.CDbCommand.execute('.$this->getText().')','system.db.CDbCommand.execute');

00253:             Yii::log('Error in executing SQL: '.$this->getText().$par,CLogger::LEVEL_ERROR,'system.db.CDbCommand');

00254:             $errorInfo = $e instanceof PDOException ? $e->errorInfo : null;


00256: throw new CDbException(Yii::t('yii','CDbCommand failed to execute the SQL statement: {error}',

00257:                 array('{error}'=>$e->getMessage())),(int)$e->getCode(),$errorInfo);

00258:         }

00259:     }


00261:     /**

00262:      * Executes the SQL statement and returns query result.

00263:      * This method is for executing an SQL query that returns result set.

00264:      * @param array $params input parameters (name=>value) for the SQL execution. This is an alternative

00265:      * to {@link bindParam} and {@link bindValue}. If you have multiple input parameters, passing

00266:      * them in this way can improve the performance. Note that you pass parameters in this way,

00267:      * you cannot bind parameters or values using {@link bindParam} or {@link bindValue}, and vice versa.

00268:      * binding methods and  the input parameters this way can improve the performance.

Stack Trace

#0 C:\Sites\yii\framework\db\ar\CActiveRecord.php(1594): CDbCommand->execute()

#1 C:\Sites\yii\framework\db\ar\CActiveRecord.php(1047): CActiveRecord->updateByPk('1', Array)

#2 C:\Sites\yii\framework\db\ar\CActiveRecord.php(764): CActiveRecord->update(NULL)

#3 C:\Sites\bizhappy\bizhappy\protected\controllers\BusinessController.php(560): CActiveRecord->save()

#4 C:\Sites\yii\framework\web\actions\CInlineAction.php(57): BusinessController->actionEditMyInfo()

#5 C:\Sites\yii\framework\web\CController.php(300): CInlineAction->run()

#6 C:\Sites\yii\framework\web\filters\CFilterChain.php(133): CController->runAction(Object(CInlineAction))

#7 C:\Sites\yii\framework\web\filters\CFilter.php(41): CFilterChain->run()

#8 C:\Sites\yii\framework\web\CController.php(1084): CFilter->filter(Object(CFilterChain))

#9 C:\Sites\yii\framework\web\filters\CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))

#10 C:\Sites\yii\framework\web\filters\CFilterChain.php(130): CInlineFilter->filter(Object(CFilterChain))

#11 C:\Sites\yii\framework\web\CController.php(283): CFilterChain->run()

#12 C:\Sites\yii\framework\web\CController.php(257): CController->runActionWithFilters(Object(CInlineAction), Array)

#13 C:\Sites\yii\framework\web\CWebApplication.php(324): CController->run('editmyinfo')

#14 C:\Sites\yii\framework\web\CWebApplication.php(121): CWebApplication->runController('business/editmy...')

#15 C:\Sites\yii\framework\base\CApplication.php(135): CWebApplication->processRequest()

#16 C:\Sites\bizhappy\bizhappy\index.php(22): CApplication->run()

#17 {main}

Mind you, the code was working at some point. Without changing the code, I get this error. Is there something that could have been changed in the db that would cause this? The table’s field structure is exactly the same. The only thing I can think of is maybe something with the collation. Or something within Yii config… Help, please!

Seems like you (or someone) added one more field to the database… that new field does not have a default value… and in the update you are not saving that field… so mysql fires this error…

Hi. Thanks for responding.

The field, id, was always in the table. It’s the pk and auto increments. It was working before! Ahh!

Don’t know what to say… you need to check the code and the table… could be that the index was removed… try to create a new user to see if inserting data is working…

The guy dealing with CRM added a trigger to the table on the id field…