Hey, I've been encountering some issues with TypeORM. I'm attempting to add a new entity to my current project and here's what I did:
I created a new entity
import { Entity, Column, PrimaryGeneratedColumn, JoinColumn, OneToOne } from 'typeorm';
@Entity()
export class Requirement {
@PrimaryGeneratedColumn("uuid")
id: string;
@Column()
seats: number;
@Column()
points: number;
}
and included it in my module
TypeOrmModule.forFeature([Requirement, ....)]
The table was successfully created in the database.
I wrote a test function to invoke:
async test(){
const req = new Requirement();
req.seats = 6;
req.points = 40;
return this.requirementRepository.save(req);
}
This is how I set up the repository:
@InjectRepository(Requirement)
private readonly requirementRepository: Repository<Requirement>,
But I received the following error
EntityMetadataNotFoundError: No metadata for "Requirement" was found.
at DataSource.getMetadata (/home/m/work/c/Website-Backend/src/data-source/DataSource.ts:427:30)
at Repository.get metadata [as metadata] (/home/m/work/c/Website-Backend/src/repository/Repository.ts:52:40)
at Repository.save (/home/m/work/c/Website-Backend/src/repository/Repository.ts:205:18)
at ProgramsService.test (/home/m/work/c/Website-Backend/libs/programs/src/programs.service.ts:38:39)
Even though the table was properly created. Just to clarify, the new entity I created is in the same directory as some other entities that are working fine. Here's my typeormconf:
...
TypeOrmModule.forRoot({
type: 'postgres',
host: process.env.POSTGRES_HOST,
port: 5433,
username: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
database: process.env.POSTGRES_DB,
entities: [__dirname + '/**/*.entity{.ts,.js}'],
autoLoadEntities: true,
logging: true,
}),
I am stuck and have tried everything, but couldn't get it to work. Thank you in advance for any help!
Although I followed the documentation, I'm still facing issues.