You can clone with
$r=!$column->allowNull && $column->defaultValue===null;
This will always return false because you can't specify a column to be NOT NULL with a default value of NULL.
Because $r always returns false rules for required fields are not generated.
Bugfix: issue #2014
Could you please specify more details? Your testing database table, database type and version, etc.
I've tested following DDL (MySQL 5.5) which represents all combinations of NULL, DEFAULT 0 and DEFAULT NULL:
create table tbl_test_table
`id` int(11) not null, /* becomes required */
`c1` int(11) not null, /* becomes required */
`c2` int(11) not null default 0, /* becomes not required */
/*`c3` int(11) not null default null,*/ /* impossible, skipped */
`c4` int(11) null, /* becomes not required, default is null */
`c5` int(11) null default 0, /* becomes not required */
`c6` int(11) null default null, /* becomes not required */
primary key (`id`)
engine=InnoDB default charset=utf8;
Your patch (provided in #2029) produces exactly same result as the current code.
I am using PHP Version 5.1.6, MySQL 5.0.22.
I have also tested with your test table and in my case both id and c1 do not become required.
Guess that this is a MySQL issue, the default value does not get NULL for id and c1.
So in that case $column->defaultValue===null will not result in true, which doesn't make these fields become required.
I've tested this with 5.0.96-community and bug does not occur (results are same as before). Could you create table i've posted above and post here results of the following code:
foreach(Yii::app()->db->schema->getTable('tbl_test_table')->columns as $column)
echo $column->name.', ';
It's interesting what you're really getting.
@heyhoo, any news on this?
I'm closing this since long time has passed without any chance to reproduce it. Please provide more details on how can i reproduce your problem and i'll reopen it.