Problem with creating a new project in chapter 5

Hi, big newbie here. Following chapter 5 of the book and while creating projects using the tests worked for me, when I try to create a new project using CRUD by typing a project name and description in the form and leaving the rest blank I get the following error:



CDbCommand failed to execute the SQL statement: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: ‘’ for column ‘create_time’ at row 1

Source File


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

00223: Yii::endProfile(‘system.db.CDbCommand.execute(’.$this->getText().’)’,‘system.db.CDbCommand.execute’);


00225: return $n;

00226: }

00227: catch(Exception $e)

00228: {

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

00230: Yii::endProfile(‘system.db.CDbCommand.execute(’.$this->getText().’)’,‘system.db.CDbCommand.execute’);

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

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


00234: throw new CDbException(Yii::t(‘yii’,‘CDbCommand failed to execute the SQL statement: {error}’,

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

00236: }

00237: }


00239: /**

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

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

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

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

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

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

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

Stack Trace

#0 C:\localhost\htdocs\yii\framework\db\ar\CActiveRecord.php(1000): CDbCommand->execute()

#1 C:\localhost\htdocs\yii\framework\db\ar\CActiveRecord.php(759): CActiveRecord->insert(NULL)

#2 C:\localhost\htdocs\trackstar\protected\controllers\TblProjectController.php(72): CActiveRecord->save()

#3 C:\localhost\htdocs\yii\framework\web\actions\CInlineAction.php(50): TblProjectController->actionCreate()

#4 C:\localhost\htdocs\yii\framework\web\CController.php(300): CInlineAction->run()

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

#6 C:\localhost\htdocs\yii\framework\web\filters\CFilter.php(41): CFilterChain->run()

#7 C:\localhost\htdocs\yii\framework\web\CController.php(1049): CFilter->filter(Object(CFilterChain))

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

#9 C:\localhost\htdocs\yii\framework\web\filters\CFilterChain.php(130): CInlineFilter->filter(Object(CFilterChain))

#10 C:\localhost\htdocs\yii\framework\web\CController.php(283): CFilterChain->run()

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

#12 C:\localhost\htdocs\yii\framework\web\CWebApplication.php(324): CController->run(‘create’)

#13 C:\localhost\htdocs\yii\framework\web\CWebApplication.php(121): CWebApplication->runController(‘tblproject/crea…’)

#14 C:\localhost\htdocs\yii\framework\base\CApplication.php(135): CWebApplication->processRequest()

#15 C:\localhost\htdocs\trackstar\index.php(13): CApplication->run()

#16 {main}

2010-10-05 20:00:45 Apache/2.2.16 (Win32) PHP/5.3.3 Yii Framework/1.1.4

any help would be much appreciated.

Are you using MySQL, or a different RDBMS as you follow along?

If MySQL, ensure your tbl_project is of the form:


id INTEGER NOT NULL auto_increment,

name varchar(128) NOT NULL,

description text NOT NULL,

create_time DATETIME default NULL,

create_user_id INTEGER default NULL,

update_time DATETIME default NULL,

update_user_id INTEGER default NULL,




It might be that due to your database configuration settings and potentially not explicitly allowing for NULL values in the DATETIME fields when creating the table, it does not like submitting blank values for these fields.

On another quick note, it looks as if you are following along in the book using the latest stable version of Yii (1.1.4), which is fine as ALL of the concepts and most of the examples translate to this newer version. However the book is using 1.1.2 and there may be some subtle differences in the code examples that surface from time to time. Just wanted you to be aware of that.

thanks, managed to figure it out!

after some looking at the mysql manuals I found that STRICT_TRANS_TABLES mode was set in my mysql configuration file which prevented it from taking dates that contain zeros.

I’ve got the same problem…

Where and how can I change this STRICT_TRANS_TABLES property on a windows machine?

I’ve just started to learn Yii using the book and had this same problem. Seems the default install of MySQL (I’m not using XAMPP or WAMPP) sets the DB mode to strict as JovanS has found - thanks for posting the solution.

It is a setting within your MySQL config file, usually in the root of your installation folder in a file called my.ini

The line may be slightly different on your installation, mine was:


…which I changed to:


Works fine.