diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index 6a6828e2f..24358c107 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -352,7 +352,7 @@ class Mysql extends DboSource { if (in_array($fields[$column->Field]['type'], $this->fieldParameters['unsigned']['types'], true)) { $fields[$column->Field]['unsigned'] = $this->_unsigned($column->Type); } - if ($fields[$column->Field]['type'] === 'timestamp' && strtoupper($column->Default) === 'CURRENT_TIMESTAMP') { + if (in_array($fields[$column->Field]['type'], array('timestamp', 'datetime')) && strtoupper($column->Default) === 'CURRENT_TIMESTAMP') { $fields[$column->Field]['default'] = null; } if (!empty($column->Key) && isset($this->index[$column->Key])) { diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php index 6c52c06d3..7cf7d4565 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php @@ -927,6 +927,41 @@ SQL; } /** + * Test that describe() ignores `default current_timestamp` in datetime columns. + * This is for MySQL >= 5.6. + * + * @return void + */ + public function testDescribeHandleCurrentTimestampDatetime() { + $name = $this->Dbo->fullTableName('timestamp_default_values'); + $sql = <<Dbo->execute($sql); + $model = new Model(array( + 'table' => 'timestamp_default_values', + 'ds' => 'test', + 'alias' => 'TimestampDefaultValue' + )); + $result = $this->Dbo->describe($model); + $this->Dbo->execute('DROP TABLE ' . $name); + + $this->assertNull($result['limit_date']['default']); + + $schema = new CakeSchema(array( + 'connection' => 'test', + 'testdescribes' => $result + )); + $result = $this->Dbo->createSchema($schema); + $this->assertContains('`limit_date` datetime NOT NULL,', $result); + } + + /** * test that a describe() gets additional fieldParameters * * @return void