Skip to content

Commit

Permalink
Don't add auto increment to columns that turn it off.
Browse files Browse the repository at this point in the history
When autoIncrement has been set to a specific value we shouldn't
overwrite the user's request. This allows integer keys to exist without
autoincrement being set.

Refs #10765
Refs #10045
  • Loading branch information
markstory committed Jun 14, 2017
1 parent b4786b3 commit 65fa367
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Database/Schema/MysqlSchema.php
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions tests/TestCase/Database/Schema/MysqlSchemaTest.php
Expand Up @@ -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],
Expand Down

0 comments on commit 65fa367

Please sign in to comment.