Skip to content

Commit b2f6b94

Browse files
committed
Fixed reset sequence when auto increment columns is not first of primary key;
1 parent 1bd682a commit b2f6b94

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/QueryBuilder.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,16 @@ public function resetSequence($table, $value = null)
426426
} else {
427427
// use master connection to get the biggest PK value
428428
$value = $this->db->useMaster(function (Connection $db) use ($tableSchema) {
429-
$key = reset($tableSchema->primaryKey);
429+
$key = false;
430+
foreach ($tableSchema->primaryKey as $name) {
431+
if ($tableSchema->columns[$name]->autoIncrement) {
432+
$key = $name;
433+
break;
434+
}
435+
}
436+
if($key === false){
437+
return 0;
438+
}
430439
return $db->createCommand("SELECT MAX({$this->db->quoteColumnName($key)}) FROM {$this->db->quoteTableName($tableSchema->name)}")->queryScalar();
431440
}) + 1;
432441
}

0 commit comments

Comments
 (0)