Symfony maker: Cannot find the entity manager for class
Cannot find the entity manager for class "App\Entity\User". Ensure entity uses attribute mapping.Short answer
MakerBundle asks Doctrine which entity manager owns a class. This error means no manager's mapping covers that namespace, or the mapping is not the attribute type MakerBundle expects. Check config/packages/doctrine.yaml: the mapping needs type attribute, a dir that holds the class and a prefix that matches its namespace.
Fix it fast
1Find out which cause you have
Read the mappings in your Doctrine config and compare each prefix and dir with the namespace line and folder of the class named in the error.
cat config/packages/doctrine.yaml head -5 src/Entity/User.php2Match what you see, then jump to its fix
- 1
The mapping shows type annotation or xml, while the entities use PHP attributes.The mapping type is not attributeFix - 2
The class is in App\Model or another namespace, and no mapping has that prefix.The class namespace does not match any mapping prefixFix - 3
doctrine.yaml defines entity_managers (default and another) with their own mappings.With several entity managers, the class is not mapped by the manager you expectFix
- 1
What does the error look like?
Cannot find the entity manager for class "App\Entity\User". Ensure entity uses attribute mapping.
Cause 1 of 3
The mapping type is not attribute
1Check
The exception message itself says to ensure the entity uses attribute mapping. DoctrineBundle's valid types are attribute, xml, php and staticphp.
grep -n -B2 -A6 "mappings" config/packages/doctrine.yaml2Fix
Set the mapping type to attribute.
doctrine:
orm:
mappings:
App:
type: attribute
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
is_bundle: false3Verify
Clear the cache and run the maker command again.
php bin/console cache:clear
php bin/console make:entity ProductConfirmed by symfony.com
Cause 2 of 3
The class namespace does not match any mapping prefix
1Check
A class is only found by a manager whose mapping prefix starts the class namespace and whose dir holds the file. Compare the namespace line in the class with prefix in doctrine.yaml.
head -5 src/Entity/User.php
grep -n "prefix\|dir:" config/packages/doctrine.yaml2Fix
Move the class under the mapped namespace, or add a mapping whose dir and prefix point to where it lives.
doctrine:
orm:
mappings:
App:
type: attribute
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
is_bundle: false3Verify
Clear the cache and run the failing maker command again; it no longer raises the error.
php bin/console cache:clear
php bin/console make:entity UserConfirmed by symfony.com
Cause 3 of 3
With several entity managers, the class is not mapped by the manager you expect
1Check
Each entity manager only manages the entities in its own mappings dir and prefix. A class outside all of them has no manager.
grep -n -A25 "entity_managers" config/packages/doctrine.yaml2Fix
Add the class's directory and prefix to the mapping of the manager that should own it, and fetch that manager by name.
doctrine:
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
Main:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src/Entity/Main'
prefix: 'App\Entity\Main'3Verify
Clear the cache and run the failing maker command again.
php bin/console cache:clear
php bin/console make:entity Main\\ProductConfirmed by symfony.com
How do I stop it coming back?
- Keep entities in the mapped folder and namespace (src/Entity and App\Entity by default).
- Use attribute mapping for new code and keep type: attribute on every mapping.
- After editing doctrine.yaml, clear the cache before running make commands.
- With multiple entity managers, give each its own folder and prefix and avoid overlaps.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Related fixes
Back end
make:migration says the metadata storage is not up to date
The metadata storage is not up to date, please run the sync-metadata-storage command to fix this issue.
Doctrine Migrations keeps its history in a table and refuses to work if it thinks that table has an old layout.
3 causes, each with a fixBack end
Airflow SSHOperator stops a long script with SSH command timed out
airflow.exceptions.AirflowException: SSH command timed out
SSHOperator waits only 10 seconds for a command by default.
3 causes, each with a fixBack end
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack end
ng serve says it cannot determine the project or target
Cannot determine project for command.
The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.
3 causes, each with a fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fix