Mysql Inset Query- Null Issue

Hi,

I am having some columns in db, which are having default value as NULL. When I execute INSERT command, from Mysql workbench/Command Line , it correctly insert ‘NULL’ for the columns, for which value is not present.

But when I fire same query from yii, it doesn’t insert ‘NULL’, instead it shows blank,

Also one more issue, for DATETIME its inserting ‘0000-00-00 00:00:00’, I want this to NULL, but I am not getting it right.

By default Yii check its model class attributes definition first and according to that create a query.and if you have define a datetime field as a null then for sure it will insert value as you have show above.And i guess it will work same in other frameworks too in the case of datetime field.

But if you want to assign that field as a null value then you can change it value like above.


$model->datetime='NULL';

Let it try. I hope it will work here.

I wrote two types of code for this




unset($model->date);


$model->date=new CDbExpression('NULL');



JUST TRY THIS


mbala