Strange error in migration

In one of my migrations, I add a column ‘dateCreated’ to all tables. This works fine for most tables, but throws a strange error on some of them:


'SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect date value: '0000-00-00' for column 'start_date' at row 1

The SQL being executed was: ALTER TABLE `payments` ADD `dateCreated` DATETIME NULL DEFAULT NULL'

A column ‘start_date’ exists allready, but I can’t see why this has anything to do with the newly created column.

This breaks my migration. The same SQL works fine when applied directly on the table in PhpMyAdmin. Does Yii add extra checks to the query, or am I missing something else?

Probably because Yii uses usually stores timestamps in ints so if you have a field which has got a datetime/timestamp type then it will not work.

Alter it to be int and do the conversion to date in the views/widgets instead?

Or - if you are using the timestamp behavior - edit/add/change the expression that it uses.

But, to be clear, I don’t insert or update ANY information at all. I add a column during a migration, and get an error about an other column’s value.

If there isn’t any rows with data, then it could perhaps be because you set a default value that is inappropriate for the column type, maybe?

That error is a SQL error - from the db server - so I don’t think that Yii is involved…

You cannot use default null on datetime field