diff --git a/core/includes/schema.inc b/core/includes/schema.inc
index 5c024a89d8..99576b0d2b 100644
--- a/core/includes/schema.inc
+++ b/core/includes/schema.inc
@@ -83,9 +83,10 @@ function drupal_get_installed_schema_version($module, $reset = FALSE, $array = F
   }
 
   if (!$versions) {
-    if (!$versions = \Drupal::keyValue('system.schema')->getAll()) {
-      $versions = [];
-    }
+    $versions = \Drupal::keyValue('system.schema')->getAll();
+    $enabled_modules = \Drupal::moduleHandler()->getModuleList();
+    $enabled_modules = array_fill_keys(array_keys($enabled_modules), \Drupal::CORE_MINIMUM_SCHEMA_VERSION);
+    $versions = array_merge($enabled_modules, $versions);
   }
 
   if ($array) {
diff --git a/core/includes/update.inc b/core/includes/update.inc
index 792e94c286..9e3a7a4e34 100644
--- a/core/includes/update.inc
+++ b/core/includes/update.inc
@@ -607,7 +607,7 @@ function update_retrieve_dependencies() {
   $return = [];
   // Get a list of installed modules, arranged so that we invoke their hooks in
   // the same order that \Drupal::moduleHandler()->invokeAll() does.
-  foreach (\Drupal::keyValue('system.schema')->getAll() as $module => $schema) {
+  foreach (drupal_get_installed_schema_version(NULL, FALSE, TRUE) as $module => $schema) {
     if ($schema == SCHEMA_UNINSTALLED) {
       // Nothing to upgrade.
       continue;
diff --git a/core/modules/system/tests/modules/update_test_no_preexisting/update_test_no_preexisting.info.yml b/core/modules/system/tests/modules/update_test_no_preexisting/update_test_no_preexisting.info.yml
new file mode 100644
index 0000000000..303d7cde54
--- /dev/null
+++ b/core/modules/system/tests/modules/update_test_no_preexisting/update_test_no_preexisting.info.yml
@@ -0,0 +1,5 @@
+name: 'Update test'
+type: module
+description: 'Support module for update testing.'
+package: Testing
+version: VERSION
diff --git a/core/modules/system/tests/modules/update_test_no_preexisting/update_test_no_preexisting.install b/core/modules/system/tests/modules/update_test_no_preexisting/update_test_no_preexisting.install
new file mode 100644
index 0000000000..7344bc0631
--- /dev/null
+++ b/core/modules/system/tests/modules/update_test_no_preexisting/update_test_no_preexisting.install
@@ -0,0 +1,13 @@
+<?php
+
+/**
+ * @file
+ * Install, update and uninstall functions for the update_test_no_preexisting module.
+ */
+
+/**
+ * Dummy update_test_no_preexisting update 8001.
+ */
+function update_test_no_preexisting_update_8001() {
+  \Drupal::state()->set('update_test_no_preexisting_update_8001', TRUE);
+}
diff --git a/core/modules/system/tests/src/Functional/UpdateSystem/NoPreExistingSchemaUpdateTest.php b/core/modules/system/tests/src/Functional/UpdateSystem/NoPreExistingSchemaUpdateTest.php
new file mode 100644
index 0000000000..3ce0ebfa19
--- /dev/null
+++ b/core/modules/system/tests/src/Functional/UpdateSystem/NoPreExistingSchemaUpdateTest.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace Drupal\Tests\system\Functional\UpdateSystem;
+
+use Drupal\Core\Database\Database;
+use Drupal\Tests\BrowserTestBase;
+use Drupal\Tests\UpdatePathTestTrait;
+
+/**
+ * Tries to update a module which has no pre-existing schema.
+ *
+ * @group Update
+ * @group legacy
+ */
+class NoPreExistingSchemaUpdateTest extends BrowserTestBase {
+  use UpdatePathTestTrait;
+
+  protected function setUp(){
+    parent::setUp();
+    $this->ensureUpdatesToRun();
+    $connection = Database::getConnection();
+
+    // Enable the update_test_no_preexisting module by altering the core.extension
+    // configuration directly, so that the schema version information is missing.
+    $extensions = $connection->select('config')
+      ->fields('config', ['data'])
+      ->condition('name', 'core.extension')
+      ->execute()
+      ->fetchField();
+    $extensions = unserialize($extensions);
+    $connection->update('config')
+      ->fields([
+        'data' => serialize(array_merge_recursive($extensions, ['module' => ['update_test_no_preexisting' => 0]])),
+      ])
+      ->condition('name', 'core.extension')
+      ->execute();
+  }
+
+  /**
+   * Test the system module updates with no dependencies installed.
+   */
+  public function testNoPreExistingSchema() {
+    $schema = \Drupal::keyValue('system.schema')->getAll();
+    $this->assertArrayNotHasKey('update_test_no_preexisting', $schema);
+    $this->assertFalse(\Drupal::state()->get('update_test_no_preexisting_update_8001', FALSE));
+
+    $this->runUpdates();
+
+    $schema = \Drupal::keyValue('system.schema')->getAll();
+    $this->assertArrayHasKey('update_test_no_preexisting', $schema);
+    $this->assertEquals('8001', $schema['update_test_no_preexisting']);
+    $this->assertTrue(\Drupal::state()->get('update_test_no_preexisting_update_8001', FALSE));
+  }
+
+}
