diff --git a/CHANGELOG.md b/CHANGELOG.md
index afd079000e..fae68dd2fa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [Fix Client error when passing asset parameter to forms #814](https://github.com/farmOS/farmOS/pull/814)
- [Update patch for Issue #3397275 to fix boolean field JSON Schema #819](https://github.com/farmOS/farmOS/pull/819)
- [Do not trim whitespace from quantity field item content #820](https://github.com/farmOS/farmOS/pull/820)
+- [Do not install base modules when --existing-config is used #821](https://github.com/farmOS/farmOS/pull/821)
## [3.1.2] 2024-02-26
diff --git a/farm.install b/farm.install
index b62aaaa0e9..d561822de8 100644
--- a/farm.install
+++ b/farm.install
@@ -106,6 +106,16 @@ function farm_install_modules(array &$install_state) {
$modules = array_merge(array_keys($all['base']), $modules);
}
+ // If the --existing-config flag is set, do not install additional modules.
+ // We assume that a site that is using configuration management has made its
+ // own decisions about which modules should be installed. By installing any
+ // additional modules here we could end up with overridden configuration. For
+ // example, it is possible that some of the optional base modules have been
+ // uninstalled in these instances, and we should not reinstall them.
+ if (!empty($install_state['parameters']['existing_config']) && $install_state['parameters']['existing_config'] === TRUE) {
+ $modules = [];
+ }
+
// If this is running in the context of a functional test, do not install any
// additional modules. This is a temporary hack.
// @see Drupal\Tests\farm_test\Functional\FarmBrowserTestBase::setUp()