首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ColumnTypeUndefinedError in TypeORM

ColumnTypeUndefinedError in TypeORM
EN

Stack Overflow用户
提问于 2021-03-01 18:57:31
回答 2查看 4.3K关注 0票数 4

有人能告诉我为什么,在启动我的项目时,我会发现以下错误:

代码语言:javascript
复制
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.

这是我上面的专栏,

代码语言:javascript
复制
    @Column({
        nullable: true
    })
    author: User;

谢谢你的帮助!

EN

回答 2

Stack Overflow用户

发布于 2021-12-13 11:30:29

由于您的tsconfig.json文件配置不正确,所以会收到此错误。将以下内容添加到文件中。

代码语言:javascript
复制
{
    "emitDecoratorMetadata": true,
    "lib": ["es5", "es6", "dom"],  
    "moduleResolution": "node",
    "target": "es5", 
}

那你就得跑

npm运行tsc

在编辑了tsconfig文件之后,进行重新编译。

票数 1
EN

Stack Overflow用户

发布于 2021-03-02 21:28:36

这是因为数据库不知道User类型。

User更改为string,错误将消失,因为数据库了解string

代码语言:javascript
复制
@Column({
        nullable: true
    })
    author: string;

如果您想要User而不是string,请使用@ManyToOne而不是@string。这将设置与用户表的外键关系,如果添加eager: true,则在使用任何TypeOrm find*方法时,User实体将与基本实体一起自动加载:

代码语言:javascript
复制
@ManyToOne(() => User, { eager: true })
author: User;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66428004

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档