我在将第二个实体添加到Nest项目中时遇到问题。它仅适用于一个实体Video
可以正常工作,但是现在当我添加另一个User
时,在编译时出现错误No repository for "User" was found. Looks like this entity is not registered in current "default" connection?
。
我在这里做什么错了?
database.module.ts
import { Module } from "@nestjs/common";
import { TypeOrmModule } from "@nestjs/typeorm";
import { ConfigModule } from "../config/config.module";
import { ConfigService } from "../config/config.service";
import { Video } from "../videos/video.entity";
import { User } from "../auth/user.entity";
@Module({
imports: [
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
type: 'postgres' as 'postgres',
host: configService.dbHost,
port: configService.dbPort,
username: configService.dbUsername,
password: configService.dbPassword,
database: configService.dbName,
entities: [Video, User],
synchronize: true
}),
inject: [ConfigService]
})
]
})
export class DatabaseModule {}
user.entity.ts
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column } from "typeorm";
Entity()
export class User extends BaseEntity {
@PrimaryGeneratedColumn()
id: number
@Column()
username: string;
@Column()
password: string;
}
答案 0 :(得分:0)
对不起,我错字了。忘记正确装饰实体。应该是@Entity()