Commit 02c3c37a by Qiang Xue

Fixes #2986.

parent c4e1416e
...@@ -255,8 +255,8 @@ class Generator extends \yii\gii\Generator ...@@ -255,8 +255,8 @@ class Generator extends \yii\gii\Generator
$db = $this->getDbConnection(); $db = $this->getDbConnection();
$uniqueIndexes = $db->getSchema()->findUniqueIndexes($table); $uniqueIndexes = $db->getSchema()->findUniqueIndexes($table);
foreach ($uniqueIndexes as $uniqueColumns) { foreach ($uniqueIndexes as $uniqueColumns) {
// Avoid validating auto incrementable columns // Avoid validating auto incremental columns
if (!$this->isUniqueColumnAutoIncrementable($table, $uniqueColumns)) { if (!$this->isColumnAutoIncremental($table, $uniqueColumns)) {
$attributesCount = count($uniqueColumns); $attributesCount = count($uniqueColumns);
if ($attributesCount == 1) { if ($attributesCount == 1) {
...@@ -579,15 +579,15 @@ class Generator extends \yii\gii\Generator ...@@ -579,15 +579,15 @@ class Generator extends \yii\gii\Generator
} }
/** /**
* Checks if any of the specified columns of an unique index is auto incrementable. * Checks if any of the specified columns is auto incremental.
* @param \yii\db\TableSchema $table the table schema * @param \yii\db\TableSchema $table the table schema
* @param array $columns columns to check for autoIncrement property * @param array $columns columns to check for autoIncrement property
* @return boolean whether any of the specified columns is auto incrementable. * @return boolean whether any of the specified columns is auto incremental.
*/ */
protected function isUniqueColumnAutoIncrementable($table, $columns) protected function isColumnAutoIncremental($table, $columns)
{ {
foreach ($columns as $column) { foreach ($columns as $column) {
if ($table->columns[$column]->autoIncrement) { if (isset($table->columns[$column]) && $table->columns[$column]->autoIncrement) {
return true; return true;
} }
} }
......
...@@ -267,7 +267,7 @@ class Schema extends \yii\db\Schema ...@@ -267,7 +267,7 @@ class Schema extends \yii\db\Schema
$sql = $this->getCreateTableSql($table); $sql = $this->getCreateTableSql($table);
$uniqueIndexes = []; $uniqueIndexes = [];
$regexp = '/UNIQUE KEY\s+([^\(^\s]+)\s*\(([^\)]+)\)/mi'; $regexp = '/UNIQUE KEY\s+([^\(\s]+)\s*\(([^\(\)]+)\)/mi';
if (preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER)) { if (preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) { foreach ($matches as $match) {
$indexName = str_replace('`', '', $match[1]); $indexName = str_replace('`', '', $match[1]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment