But the app crashes with an error: "Entity metadata not found for User". What is the likely cause?
medium
A. The User entity class is not imported or registered correctly in entities array
B. The database connection details are incorrect
C. synchronize: true is not allowed with Postgres
D. TypeOrmModule.forRoot() must be called inside a service, not a module
Solution
Step 1: Analyze the error message
"Entity metadata not found for User" means TypeORM cannot find the User entity definition.
Step 2: Check entities registration
This usually happens if the User entity class is not imported or not included properly in the entities array of the config.
Final Answer:
The User entity class is not imported or registered correctly in entities array -> Option A
Quick Check:
Missing entity import = metadata error [OK]
Hint: Always import and add entities to entities array [OK]
Common Mistakes:
Forgetting to import entity classes
Misplacing entities array outside forRoot config
Assuming synchronize causes this error
5. You want to set up TypeORM in a NestJS app to connect to a MySQL database, but only synchronize the schema during development, not in production. Which setup correctly achieves this?