diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index a47f24092f..9030302d8a 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -10,6 +10,7 @@ Yii Framework 2 Change Log - Bug #9796: Initialization of not existing `yii\grid\ActionColumn` default buttons (arogachev) - Bug #12681: Changed `data` column type from `text` to `blob` to handle null-byte (`\0`) in serialized RBAC rule properly (silverfire) - Bug #12714: Fixed `yii\validation\EmailValidator` to prevent false-positives checks when property `checkDns` is set to `true` (silverfire) +- Bug #12735: Fixed `yii\console\controllers\MigrateController` creating multiple primary keys for field `bigPrimaryKey:unsigned` (SG5) - Bug #12791: Fixed `yii\behaviors\AttributeTypecastBehavior` unable to automatically detect `attributeTypes`, triggering PHP Fatal Error (klimov-paul) - Bug #12803, #12921: Fixed BC break in `yii.activeForm.js` introduced in #11999. Reverted commit 3ba72da (silverfire) - Bug #12810: Fixed `yii\rbac\DbManager::getChildRoles()` and `yii\rbac\PhpManager::getChildRoles()` throws an exception when role has no child roles (mysterydragon) diff --git a/framework/console/controllers/MigrateController.php b/framework/console/controllers/MigrateController.php index a91c6220ef..2b9866afbf 100644 --- a/framework/console/controllers/MigrateController.php +++ b/framework/console/controllers/MigrateController.php @@ -462,7 +462,7 @@ class MigrateController extends BaseMigrateController protected function addDefaultPrimaryKey(&$fields) { foreach ($fields as $field) { - if ($field['decorators'] === 'primaryKey()' || $field['decorators'] === 'bigPrimaryKey()') { + if (false !== strripos($field['decorators'], 'primarykey()')) { return; } } diff --git a/tests/data/console/migrate_create/create_unsigned_big_pk.php b/tests/data/console/migrate_create/create_unsigned_big_pk.php new file mode 100644 index 0000000000..54b357423d --- /dev/null +++ b/tests/data/console/migrate_create/create_unsigned_big_pk.php @@ -0,0 +1,32 @@ +createTable('{table}', [ + 'brand_id' => \$this->bigPrimaryKey()->unsigned(), + ]); + } + + /** + * @inheritdoc + */ + public function down() + { + \$this->dropTable('{table}'); + } +} + +CODE; diff --git a/tests/data/console/migrate_create/create_unsigned_pk.php b/tests/data/console/migrate_create/create_unsigned_pk.php new file mode 100644 index 0000000000..1c6984326b --- /dev/null +++ b/tests/data/console/migrate_create/create_unsigned_pk.php @@ -0,0 +1,32 @@ +createTable('{table}', [ + 'brand_id' => \$this->primaryKey()->unsigned(), + ]); + } + + /** + * @inheritdoc + */ + public function down() + { + \$this->dropTable('{table}'); + } +} + +CODE; diff --git a/tests/framework/console/controllers/MigrateControllerTest.php b/tests/framework/console/controllers/MigrateControllerTest.php index c22cd74733..c95d1cb253 100644 --- a/tests/framework/console/controllers/MigrateControllerTest.php +++ b/tests/framework/console/controllers/MigrateControllerTest.php @@ -95,6 +95,14 @@ class MigrateControllerTest extends TestCase 'fields' => 'title:primaryKey,body:text:notNull,price:money(11,2)', ]); + $this->assertCommandCreatedFile('create_unsigned_pk', $migrationName, $table, [ + 'fields' => 'brand_id:primaryKey:unsigned', + ]); + + $this->assertCommandCreatedFile('create_unsigned_big_pk', $migrationName, $table, [ + 'fields' => 'brand_id:bigPrimaryKey:unsigned', + ]); + $this->assertCommandCreatedFile('create_id_pk', $migrationName, $table, [ 'fields' => 'id:primaryKey, address:string,