diff --git a/core/Command/Db/AddMissingIndices.php b/core/Command/Db/AddMissingIndices.php
index ec36400d291e9..eec0aedce1119 100644
--- a/core/Command/Db/AddMissingIndices.php
+++ b/core/Command/Db/AddMissingIndices.php
@@ -86,14 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($schema->hasTable($toReplaceIndex['tableName'])) {
$table = $schema->getTable($toReplaceIndex['tableName']);
- $allOldIndicesExists = true;
- foreach ($toReplaceIndex['oldIndexNames'] as $oldIndexName) {
- if (!$table->hasIndex($oldIndexName)) {
- $allOldIndicesExists = false;
- }
- }
-
- if (!$allOldIndicesExists) {
+ if ($table->hasIndex($toReplaceIndex['newIndexName'])) {
continue;
}
@@ -110,8 +103,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
foreach ($toReplaceIndex['oldIndexNames'] as $oldIndexName) {
- $output->writeln('Removing ' . $oldIndexName . ' index from the ' . $table->getName() . ' table');
- $table->dropIndex($oldIndexName);
+ if ($table->hasIndex($oldIndexName)) {
+ $output->writeln('Removing ' . $oldIndexName . ' index from the ' . $table->getName() . ' table');
+ $table->dropIndex($oldIndexName);
+ }
}
if (!$dryRun) {