diff --git a/src/Database/Schema/MysqlSchema.php b/src/Database/Schema/MysqlSchema.php index fb161a0aa3d..28d4d727c45 100644 --- a/src/Database/Schema/MysqlSchema.php +++ b/src/Database/Schema/MysqlSchema.php @@ -382,7 +382,8 @@ public function columnSql(TableSchema $schema, $name) } $addAutoIncrement = ( [$name] == (array)$schema->primaryKey() && - !$schema->hasAutoincrement() + !$schema->hasAutoincrement() && + !isset($data['autoIncrement']) ); if (in_array($data['type'], ['integer', 'biginteger']) && ($data['autoIncrement'] === true || $addAutoIncrement) diff --git a/tests/TestCase/Database/Schema/MysqlSchemaTest.php b/tests/TestCase/Database/Schema/MysqlSchemaTest.php index 1bbdf2f6e70..b6e2e9304ea 100644 --- a/tests/TestCase/Database/Schema/MysqlSchemaTest.php +++ b/tests/TestCase/Database/Schema/MysqlSchemaTest.php @@ -592,6 +592,11 @@ public static function columnSqlProvider() ['type' => 'integer', 'length' => 20, 'autoIncrement' => true], '`post_id` INTEGER(20) AUTO_INCREMENT' ], + [ + 'post_id', + ['type' => 'integer', 'length' => 20, 'null' => false, 'autoIncrement' => false], + '`post_id` INTEGER(20) NOT NULL' + ], [ 'post_id', ['type' => 'biginteger', 'length' => 20, 'autoIncrement' => true],