{"record":{"id":"d5e0539e4c44b046","repo":"doctrine/orm","slug":"no-metadata-cache-driver-is-configured-on-given-en","errorCode":null,"errorMessage":"No Metadata cache driver is configured on given EntityManager.","messagePattern":"No Metadata cache driver is configured on given EntityManager\\.","errorType":"console","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Tools/Console/Command/ClearCache/MetadataCommand.php","lineNumber":40,"sourceCode":"    {\n        $this->setName('orm:clear-cache:metadata')\n             ->setDescription('Clear all metadata cache of the various cache drivers')\n             ->addOption('em', null, InputOption::VALUE_REQUIRED, 'Name of the entity manager to operate on')\n             ->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, cache entries will be flushed instead of deleted/invalidated.')\n             ->setHelp(<<<'EOT'\nThe <info>%command.name%</info> command is meant to clear the metadata cache of associated Entity Manager.\nEOT);\n    }\n\n    protected function execute(InputInterface $input, OutputInterface $output): int\n    {\n        $ui = (new SymfonyStyle($input, $output))->getErrorStyle();\n\n        $em          = $this->getEntityManager($input);\n        $cacheDriver = $em->getConfiguration()->getMetadataCache();\n\n        if (! $cacheDriver) {\n            throw new InvalidArgumentException('No Metadata cache driver is configured on given EntityManager.');\n        }\n\n        $ui->comment('Clearing <info>all</info> Metadata cache entries');\n\n        $result  = $cacheDriver->clear();\n        $message = $result ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';\n\n        $ui->success($message);\n\n        return 0;\n    }\n}\n","sourceCodeStart":22,"sourceCodeEnd":53,"githubUrl":"https://github.com/doctrine/orm/blob/d9b9ff73016bf598ae07515f97289ce8074e97a5/src/Tools/Console/Command/ClearCache/MetadataCommand.php#L22-L53","documentation":"orm:clear-cache:metadata clears the metadata cache through $em->getConfiguration()->getMetadataCache(). When the configuration never set a metadata cache, that getter returns null and the command throws InvalidArgumentException — there is no metadata cache to clear. Unlike ORM 2, this ORM version does not silently pick a default cache implementation.","triggerScenarios":"Running orm:clear-cache:metadata on an EntityManager built from a Configuration that never called setMetadataCache() (or doctrine-bundle's metadata_cache_driver); custom EM factories that only configure a query or result cache.","commonSituations":"ORM 2 to 3 upgrades where implicit default caching disappeared; hand-rolled EntityManager bootstraps; CLI contexts wired to a different, cache-less connection than the web app.","solutions":["Configure a metadata cache where you intend to clear it: $config->setMetadataCache($psrAdapter) or doctrine-bundle orm metadata_cache_driver.","If you intentionally run without a metadata cache, remove the command from cache-clear routines.","Verify in the same CLI context: $em->getConfiguration()->getMetadataCache() !== null."],"exampleFix":"// before: no metadata cache configured\n$ php bin/console doctrine:orm:clear-cache:metadata\n// InvalidArgumentException: No Metadata cache driver is configured...\n\n// after: configure one\n$config = ORMSetup::createAttributeMetadataConfiguration($paths, true);\n$config->setMetadataCache(new Symfony\\Component\\Cache\\Adapter\\PhpFilesAdapter(\n    'orm_metadata', 0, $cacheDir\n));","handlingStrategy":"validation","validationCode":"if ($em->getConfiguration()->getMetadataCache() === null) {\n    // no metadata cache configured: nothing to clear, skip the command\n    return 0;\n}\n// run orm:clear-cache:metadata","typeGuard":null,"tryCatchPattern":"In deploy scripts, catch \\InvalidArgumentException around the command call and log 'metadata cache not configured' as info instead of failing the pipeline.","preventionTips":["Set explicit cache pools (metadata/query/result) in every environment that runs cache commands.","Reuse the same cache configuration code path for web and CLI.","Smoke-test deploy scripts in an environment identical to production."],"tags":["doctrine-orm","console","cache","metadata-cache","cli","symfony"],"backgroundTag":"missing-cache-configuration","analyzedSha":"d9b9ff73016bf598ae07515f97289ce8074e97a5","analyzedAt":"2026-08-21T06:13:15.863Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}