diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php
index 447079110924f19ec7e4f1a1f13ace525479058c..42c3de3ea1eeae033d58b5e571eac52d805c373d 100644
--- a/lib/private/DB/MigrationService.php
+++ b/lib/private/DB/MigrationService.php
@@ -453,8 +453,6 @@ class MigrationService {
 			$toSchema = $instance->changeSchema($this->output, function () use ($toSchema) {
 				return $toSchema ?: new SchemaWrapper($this->connection);
 			}, ['tablePrefix' => $this->connection->getPrefix()]) ?: $toSchema;
-
-			$this->markAsExecuted($version);
 		}
 
 		if ($toSchema instanceof SchemaWrapper) {
@@ -466,6 +464,10 @@ class MigrationService {
 			$this->connection->migrateToSchema($targetSchema);
 			$toSchema->performDropTableCalls();
 		}
+
+		foreach ($toBeExecuted as $version) {
+			$this->markAsExecuted($version);
+		}
 	}
 
 	/**