Createcommand()->Insert Returns Cdbexception 1406 Data Too Long For True Value.

This is ok.


Yii::app()->db->createCommand()->insert('people', array('Married'=>false,));



This will return error!


Yii::app()->db->createCommand()->insert('people', array('Married'=>true,));



Bug?

It sounds like PHP’s true is being mapped to something that the database engine doesn’t like. PHP’s false is generally mapped to the empty string in a string context, which is probably why that didn’t trigger a length error.

Please provide:

  • The type of database (eg. MySQL);

  • The database column type, with any length constraints;

  • Your model rules.

MySql ver = 5.5.22

Data type = Bit(1)

Model rules = array(‘Married’, ‘numerical’, ‘integerOnly’=>true),

It seems like it’s a problem with using a bit field. Searching google for “php mysql bit field” brings up a number of possible avenues.

I’d suggest using an integer field type if you want it to play nicely with PHP. Otherwise, you’ll have to alter your database queries to coerce the field into a suitable format.

I suppose it depends how much of an issue the additional storage requirements would be for your database.