doctrine/orm · error · InvalidArgumentException
No Metadata cache driver is configured on given EntityManage
Error message
No Metadata cache driver is configured on given EntityManager.
What it means
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.
Source
Thrown at src/Tools/Console/Command/ClearCache/MetadataCommand.php:40
{
$this->setName('orm:clear-cache:metadata')
->setDescription('Clear all metadata cache of the various cache drivers')
->addOption('em', null, InputOption::VALUE_REQUIRED, 'Name of the entity manager to operate on')
->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, cache entries will be flushed instead of deleted/invalidated.')
->setHelp(<<<'EOT'
The <info>%command.name%</info> command is meant to clear the metadata cache of associated Entity Manager.
EOT);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();
$em = $this->getEntityManager($input);
$cacheDriver = $em->getConfiguration()->getMetadataCache();
if (! $cacheDriver) {
throw new InvalidArgumentException('No Metadata cache driver is configured on given EntityManager.');
}
$ui->comment('Clearing <info>all</info> Metadata cache entries');
$result = $cacheDriver->clear();
$message = $result ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';
$ui->success($message);
return 0;
}
}
View on GitHub (pinned to d9b9ff7301)
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.
Example fix
// before: no metadata cache configured
$ php bin/console doctrine:orm:clear-cache:metadata
// InvalidArgumentException: No Metadata cache driver is configured...
// after: configure one
$config = ORMSetup::createAttributeMetadataConfiguration($paths, true);
$config->setMetadataCache(new Symfony\Component\Cache\Adapter\PhpFilesAdapter(
'orm_metadata', 0, $cacheDir
)); Defensive patterns
Strategy: validation
Validate before calling
if ($em->getConfiguration()->getMetadataCache() === null) {
// no metadata cache configured: nothing to clear, skip the command
return 0;
}
// run orm:clear-cache:metadata Try / catch
In deploy scripts, catch \InvalidArgumentException around the command call and log 'metadata cache not configured' as info instead of failing the pipeline.
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- No second-level cache is configured on the given EntityManag
- No second-level cache is configured on the given EntityManag
- No Query cache driver is configured on given EntityManager.
- No second-level cache is configured on the given EntityManag
- No Result cache driver is configured on given EntityManager.
AI-assisted analysis of doctrine/orm@d9b9ff7301 (2026-08-21).
Data as JSON: /api/errors/d5e0539e4c44b046.
Report an issue: GitHub.