【发布时间】:2021-08-05 09:44:28
【问题描述】:
我有一个 Nestjs 数据库模块,它运行良好
@Module({
imports: [
TypeOrmModule.forRootAsync({
useFactory: () => {
return {
name: 'default', // <=== here
type: "mysql",
...
};
},
}),
TypeOrmModule.forFeature(entities, 'default'), // <=== here
],
exports: [TypeOrmModule],
})
export class DBModule {}
如果我将连接名称更改为其他名称,而不是“默认”,则说“测试”,我会收到错误
@Module({
imports: [
TypeOrmModule.forRootAsync({
useFactory: () => {
return {
name: 'test', // <=== here
type: "mysql",
...
};
},
}),
TypeOrmModule.forFeature(entities, 'test'), // <=== here
],
exports: [TypeOrmModule],
})
export class DBModule {}
[Nest] 10746 - 05/15/2021, 5:55:34 PM [ExceptionHandler] Nest can't resolve dependencies of the test_UserEntityRepository (?). Please make sure that the argument testConnection at index [0] is available in the TypeOrmModule context.
Potential solutions:
- If testConnection is a provider, is it part of the current TypeOrmModule?
- If testConnection is exported from a separate @Module, is that module imported within TypeOrmModule?
@Module({
imports: [ /* the Module containing testConnection */ ]
})
只有在我使用 TypeOrmModule.forRootAsync 时才会出现错误接缝 对于 TypeOrmModule.forRoot 如果有效!
是否有任何不同的方式来表示连接名称?我需要添加另一个连接,但由于此错误而无法执行。真的很想用'forRootAsync'
【问题讨论】:
标签: connection nestjs typeorm