有人能告诉我为什么,在启动我的项目时,我会发现以下错误:
ColumnTypeUndefinedError: Column type for Order#author is not defined and cannot be guessed. Make sure you have turned on an "emitDecoratorMetadata": true option in tsconfig.json. Also make sure you have imported "reflect-metadata" on top of the main entry file in your application (before any entity imported).If you are using JavaScript instead of TypeScript you must explicitly provide a column type.这是我上面的专栏,
@Column({
nullable: true
})
author: User;谢谢你的帮助!
发布于 2021-12-13 11:30:29
由于您的tsconfig.json文件配置不正确,所以会收到此错误。将以下内容添加到文件中。
{
"emitDecoratorMetadata": true,
"lib": ["es5", "es6", "dom"],
"moduleResolution": "node",
"target": "es5",
}那你就得跑
npm运行tsc
在编辑了tsconfig文件之后,进行重新编译。
发布于 2021-03-02 21:28:36
这是因为数据库不知道User类型。
将User更改为string,错误将消失,因为数据库了解string
@Column({
nullable: true
})
author: string;如果您想要User而不是string,请使用@ManyToOne而不是@string。这将设置与用户表的外键关系,如果添加eager: true,则在使用任何TypeOrm find*方法时,User实体将与基本实体一起自动加载:
@ManyToOne(() => User, { eager: true })
author: User;https://stackoverflow.com/questions/66428004
复制相似问题