achertovsky / yii2-debug-cli

7 stars 4 forks source link

Migration fail on Mysql INNODB table #2

Open ruskush opened 3 years ago

ruskush commented 3 years ago

When I trying apply migration on Mysql database version 5.5 which is utf8mb4 encoded - it fails with messages:

'SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
The SQL being executed was: ALTER TABLE `error_hub` ADD CONSTRAINT `pd_id` PRIMARY KEY (`id`)'

'SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
The SQL being executed was: ALTER TABLE `error_hub` ADD UNIQUE INDEX `i_issue_id` (`issue_id`)'

One of the solutions - use limitation to varchar indexed fields: VARCHAR(191):

        $this->createTable(
            'error_hub',
            [
                'id' => $this->string(191)->notNull(),
                'text' => $this->text(),
                'trace' => $this->text(),
                'category' => $this->string(),
                'issue_id' => $this->string(191),
                'count' => $this->integer(),
                'created_at' => $this->integer(),
                'updated_at' => $this->integer(),
            ]
        );
        $this->addPrimaryKey("pd_id", '{{%error_hub}}', 'id');
        $this->createIndex('i_issue_id', '{{%error_hub}}', 'issue_id', true);
        $this->createIndex('i_count', '{{%error_hub}}', 'count');