diff --git a/lib/Cake/Database/Schema/MysqlSchema.php b/lib/Cake/Database/Schema/MysqlSchema.php index 3b5489e4594..71580b2005d 100644 --- a/lib/Cake/Database/Schema/MysqlSchema.php +++ b/lib/Cake/Database/Schema/MysqlSchema.php @@ -199,7 +199,18 @@ public function dropTableSql(Table $table) { */ public function createTableSql(Table $table, $columns, $constraints, $indexes) { $content = implode(",\n", array_merge($columns, $constraints, $indexes)); - return [sprintf("CREATE TABLE `%s` (\n%s\n)", $table->name(), $content)]; + $content = sprintf("CREATE TABLE `%s` (\n%s\n)", $table->name(), $content); + $options = $table->options(); + if (isset($options['engine'])) { + $content .= sprintf(" ENGINE=%s", $options['engine']); + } + if (isset($options['charset'])) { + $content .= sprintf(" DEFAULT CHARSET=%s", $options['charset']); + } + if (isset($options['collate'])) { + $content .= sprintf(" COLLATE=%s", $options['collate']); + } + return [$content]; } /** diff --git a/lib/Cake/Test/TestCase/Database/Schema/MysqlSchemaTest.php b/lib/Cake/Test/TestCase/Database/Schema/MysqlSchemaTest.php index 20ac993c157..fa25481964c 100644 --- a/lib/Cake/Test/TestCase/Database/Schema/MysqlSchemaTest.php +++ b/lib/Cake/Test/TestCase/Database/Schema/MysqlSchemaTest.php @@ -543,6 +543,11 @@ public function testCreateSql() { ->addConstraint('primary', [ 'type' => 'primary', 'columns' => ['id'] + ]) + ->options([ + 'engine' => 'InnoDB', + 'charset' => 'utf8', + 'collate' => 'utf8_general_ci', ]); $expected = <<createSql($connection); $this->assertCount(1, $result);