Skip to content

Commit 48c6e9f

Browse files
Merge pull request #19342 from liviuconcioiu/primary-key
Fix add PRIMARY key from More drop-down
2 parents 23af05f + 6b8a93e commit 48c6e9f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Controllers/Table/Structure/AbstractIndexController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function handleIndexCreation(ServerRequest $request, string $indexType):
3939
Assert::allString($selected);
4040

4141
if ($indexType === 'PRIMARY') {
42-
$hasPrimaryKey = $this->indexes->hasPrimaryKey(Current::$table);
42+
$hasPrimaryKey = $this->indexes->hasPrimaryKey(Current::$database, Current::$table);
4343
$statement = Generator::getAddPrimaryKeyStatement(Current::$table, $selected[0], $hasPrimaryKey);
4444
} else {
4545
$statement = Generator::getAddIndexSql($indexType, Current::$table, $selected);

src/Table/Indexes.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,11 @@ public function executeAddIndexSql(string|DatabaseName $db, string $sql): Messag
189189
return Message::success();
190190
}
191191

192-
public function hasPrimaryKey(string|TableName $table): bool
192+
public function hasPrimaryKey(string|DatabaseName $db, string|TableName $table): bool
193193
{
194+
$this->dbi->selectDb($db);
194195
$result = $this->dbi->query('SHOW KEYS FROM ' . Util::backquote($table));
196+
195197
foreach ($result as $row) {
196198
if ($row['Key_name'] === 'PRIMARY') {
197199
return true;

0 commit comments

Comments
 (0)