ruckus / ruckusing-migrations

Database migrations for PHP ala ActiveRecord Migrations with support for MySQL, Postgres, SQLite
Other
506 stars 95 forks source link

MySQL timestamp needs a NULL attribute when null == true #162

Closed larsnystrom closed 9 years ago

larsnystrom commented 9 years ago

If you try to add a column like this:

$table->column('modified', 'timestamp', [
    'null' => true,
    'default' => null,
]);

the result will be SQL like this:

...
`modified` timestamp,
...

which ends up creating a column which do not allow null values. If you want to allow null values in timestamp columns you have to add the NULL attribute, like this:

...
`modified` timestamp NULL,
....

You can fix this by changing line 1165 in lib/Ruckusing/Adapter/MySQL/Base.php to

if (array_key_exists('null', $options)) {
    if ($options['null'] === false || $options['null'] === 'NO') {
        $sql .= " NOT NULL";
    } elseif ('timestamp' === $type) {
        $sql .= " NULL";
    }
}