Bug: EntityMetadataNotFoundError: No metadata for "Entity" was found.
golubvladimir opened this issue · 7 comments
Versions
- Node: 18.4
- OS: MacOS 13
Reproduction
My project - https://github.com/golubvladimir/pizza-app/tree/backend/add-seeding
Seeders and factories - https://github.com/golubvladimir/pizza-app/tree/backend/add-seeding/backend/src/database
Steps to reproduce
run command by npm - npm run seed
What is Expected?
Works fine
What is actually happening?
EntityMetadataNotFoundError: No metadata for "CategoryEntity" was found.
I have found same problem - #219
I tried same way, but it doesn't work for me.
Error - EntityMetadataNotFoundError: No metadata for "CategoryEntity" was found.
//seeds: [`${ process.cwd() }/src/database/seeds/**/*{.js,.ts}`],
//factories: [`${ process.cwd() }/src/database/factories/**/*{.js,.ts}`]
seeds: [
CategorySeeder
],
factories: [
CategoryFactory
]
@golubvladimir your problem is not directly related to this library 🙈, but it was very helpful that you could provide me with a repo to reproduce
You missed to register your database entities for the DataSource 😅
https://github.com/golubvladimir/pizza-app/blob/backend/add-seeding/backend/data-source.ts
The file should look like this:
import { DataSource, DataSourceOptions } from 'typeorm';
import { SeederOptions } from 'typeorm-extension';
console.log(process.cwd())
const options: DataSourceOptions & SeederOptions = {
type: 'mysql',
database: 'pizza_db',
port: 8889,
host: 'localhost',
password: 'root',
username: 'root',
entities: [
'src/categories/entities/*{.js,.ts}',
'src/products/entities/*{.js,.ts}',
],
seeds: [`src/database/seeds/**/*{.js,.ts}`],
factories: [`src/database/factories/**/*{.js,.ts}`]
};
export const dataSource = new DataSource(options);
PS: You can also register your entities by class reference instead of path reference.
https://typeorm.io/#quick-start
It helped. Thanks.
Glad it helped. Your welcome 🤗
I'm having the same issue, but I'm registering by entities, :( any idea why is this happening ?
export const dataSourceOptions: DataSourceOptions & SeederOptions = {
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'postgres',
password: 'password',
database: 'db',
synchronize: true,
//
entities: ['dist/**/*.entity{.ts,.js}'],
migrations: ['dist/db/migrations/*.js'],
seeds: ['src/db/seeds/**/*{.ts,.js}'],
// factories: ['db/factories/**/*{.ts,.js}'],
};
same here!
FYI: In my case, I replaced the entity path with one that included ../ and that fixed it
For example, I changed path from
import { UserEntity } from 'src/modules/user/entity/user.entity';
to
import { UserEntity } from '../../src/modules/user/entity/user.entity';