CDbException: Incorrect decimal value '' for column 'price'

I just started my first yii project, generated with gii.

My database table has a decimal field "price" created with the following migration:

$this->createTable('tbl_products', array(


	'price' => 'DECIMAL(15,6)'

When I create a new product and try to save the edit form, the following CDbException occurs:

CDbCommand konnte das SQL-Statement nicht ausführen: SQLSTATE[HY000]: General error: 1366 Incorrect decimal value: ‘’ for column ‘price’ at row 1. The SQL statement executed was: INSERT INTO tbl_products

I need to save products without a price.

How to implement this?

The mysql price column is allowed to save NULL values.

Try setting the price’s rules’ setOnEmpty to false:

public function rules()


    return array(

        array('price', 'default', 'setOnEmpty'=>false)



That works fine.



I had to change this to

 array('price', 'default', 'setOnEmpty'=>true, 'value' => null),

because the edit field value was not saved to database.