I'm using TypeORM with the fallowing configuration file: ormconfig.json
{
"type": "mysql",
"host": "localhost",
"port": 3306,
"username": "root",
"password": "my-secret-pw",
"database": "mytestdb",
}
My Entities files are stored on the ./src/bar/entity directory. I always get the following error:
RepositoryNotFoundError: No repository for "myTable" was found. Looks like this entity is not registered in current "default" connection?
The Entity is found when I manually add the directory to the configuration file:
{
...
"entities": ["src/bar/entity/**/*.ts"]
}
My Entity is defined like:
@Entity('myTable')
export default class MyTable {
@PrimaryGeneratedColumn()
public id: number;
...
How can I allow the TypeORM to find those entities without setting manually in the configuration file for each directory?
The most common case you described is to have separate entities
directory which consists only of Entity declarations.
{
...
"entities": ["src/bar/entities/**/*.ts"]
}
Another approach would be importing each entity separately:
import {User} from "./payment/entity/User";
import {Post} from "./blog/entity/Post";
{
...
"entities": [User, Post]
}
For me it helped to include also src
directory to ormconfig.json
:
"entities": [
"dist/**/*.entity{.ts,.js}",
"src/**/*.entity{.ts,.js}"
],
For me the answer was
{
...
entities: [join(__dirname, '/../**/**.entity{.ts,.js}')],
}
I've found the exapmle here https://github.com/nestjs/nest/blob/master/sample/05-sql-typeorm/src/app.module.ts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With