diff --git a/config/app.example.php b/config/app.example.php index 3fc952b0..d5b367d9 100644 --- a/config/app.example.php +++ b/config/app.example.php @@ -9,5 +9,6 @@ 'unsigned_primary_keys' => null, // Default false 'unsigned_ints' => null, // Default false, make sure this is aligned with the above config 'column_null_default' => null, // Default false + 'default_collation' => null, // Default null (uses database collation). Set to e.g. 'utf8mb4_unicode_ci' to override. ], ]; diff --git a/docs/en/writing-migrations.rst b/docs/en/writing-migrations.rst index 161c803d..4272fbc1 100644 --- a/docs/en/writing-migrations.rst +++ b/docs/en/writing-migrations.rst @@ -546,10 +546,9 @@ In addition, the MySQL adapter supports following options: Option Platform Description ========== ================ =========== comment MySQL, Postgres set a text comment on the table -collation MySQL, SqlServer the default collation for a table if different than the database. +collation MySQL, SqlServer set the table collation *(defaults to database collation)* row_format MySQL set the table row format engine MySQL define table engine *(defaults to ``InnoDB``)* -collation MySQL define table collation *(defaults to ``utf8mb4_unicode_ci``)* signed MySQL whether the primary key is ``signed`` *(defaults to ``false``)* limit MySQL set the maximum length for the primary key ========== ================ =========== diff --git a/src/Db/Adapter/MysqlAdapter.php b/src/Db/Adapter/MysqlAdapter.php index 0873581a..b1d8a182 100644 --- a/src/Db/Adapter/MysqlAdapter.php +++ b/src/Db/Adapter/MysqlAdapter.php @@ -251,9 +251,13 @@ public function createTable(TableMetadata $table, array $columns = [], array $in // This method is based on the MySQL docs here: https://dev.mysql.com/doc/refman/5.1/en/create-index.html $defaultOptions = [ 'engine' => 'InnoDB', - 'collation' => 'utf8mb4_unicode_ci', ]; + $collation = Configure::read('Migrations.default_collation'); + if ($collation) { + $defaultOptions['collation'] = $collation; + } + $options = array_merge( $defaultOptions, array_intersect_key($this->getOptions(), $defaultOptions),