doctrine/orm · error · RuntimeException

The Doctrine setup tool cannot configure caches without symf

Error message

The Doctrine setup tool cannot configure caches without symfony/cache. Please add symfony/cache as explicit dependency or pass your own cache implementation.

What it means

ORMSetup::createAttributeMetadataConfiguration() (and the XML/YAML variants) need a PSR-6 cache; when you pass cache: null the setup tool tries to build one from symfony/cache (ArrayAdapter in dev mode, APCu/Filesystem in production). If the symfony/cache package is not installed, it throws this RuntimeException instead of silently running uncached.

Source

Thrown at src/ORMSetup.php:181

        $config = new Configuration();
        $config->setMetadataCache($cache);
        $config->setQueryCache($cache);
        $config->setResultCache($cache);

        return $config;
    }

    private static function createCacheInstance(
        bool $isDevMode,
        string|null $cacheNamespaceSeed,
        CacheItemPoolInterface|null $cache,
    ): CacheItemPoolInterface {
        if ($cache !== null) {
            return $cache;
        }

        if (! class_exists(ArrayAdapter::class)) {
            throw new RuntimeException(
                'The Doctrine setup tool cannot configure caches without symfony/cache.'
                . ' Please add symfony/cache as explicit dependency or pass your own cache implementation.',
            );
        }

        if ($isDevMode) {
            return new ArrayAdapter();
        }

        $namespace = 'dc2_' . md5($cacheNamespaceSeed ?? 'default');

        if (extension_loaded('apcu') && apcu_enabled()) {
            return new ApcuAdapter($namespace);
        }

        if (MemcachedAdapter::isSupported()) {
            return new MemcachedAdapter(MemcachedAdapter::createConnection('memcached://127.0.0.1'), $namespace);
        }

View on GitHub (pinned to d9b9ff7301)

Solutions

  1. composer require symfony/cache
  2. Or pass your own PSR-6 pool as the cache argument: ORMSetup::createAttributeMetadataConfiguration($paths, $devMode, proxyDir, $myCachePool)
  3. In Symfony full-stack apps, let the framework bundle configure the ORM instead of calling ORMSetup directly

Example fix

// before
$config = ORMSetup::createAttributeMetadataConfiguration([__DIR__.'/src/Entity'], true);
// throws: symfony/cache missing

// after
// composer require symfony/cache
// or:
$config = ORMSetup::createAttributeMetadataConfiguration(
    [__DIR__.'/src/Entity'], true, null, new MyPsr6Pool()
);
Defensive patterns

Strategy: validation

Validate before calling

if (! class_exists(\Symfony\Component\Cache\Adapter::class)) {
    throw new RuntimeException('Run: composer require symfony/cache');
}
$config = ORMSetup::createAttributeMetadataConfiguration($paths, $devMode);

Prevention

When it happens

Trigger: ORMSetup::createAttributeMetadataConfiguration($paths, $devMode) without the optional $cache argument while symfony/cache is absent from composer dependencies; slim project templates that require doctrine/orm but not symfony/cache.

Common situations: New projects or microservice builds adding doctrine/orm alone; upgrading where the cache argument changed; Symfony framework apps normally have symfony/cache already, so this bites standalone Silex/Slim/CLI tooling.

Related errors


AI-assisted analysis of doctrine/orm@d9b9ff7301 (2026-08-21). Data as JSON: /api/errors/b09d9caf8febed4b. Report an issue: GitHub.