TypeORM(MySQL)无法创建多对一/一对多关系

0ve6wy6x  于 2022-11-28  发布在  Mysql
关注(0)|答案(1)|浏览(281)

我直接遵循TypeORM的文档here
我尝试创建的实体关系如下(& R):

报告实体
@Entity({name: "reports"})
export class ReportsEntity {
    @PrimaryGeneratedColumn('uuid')
    uuid: string;

    @PrimaryColumn()
    @ManyToOne(() => ApplicationsEntity, (application) => application.reports)
    application: ApplicationsEntity

    @Column()
    description: string

    @Column({ type: 'timestamp' })
    @CreateDateColumn()
    createdAt: Date;

    @Column({ type: 'timestamp' })
    @UpdateDateColumn()
    updatedAt: Date;
}
应用程序实体
@Entity({name: "applications"})
export class ApplicationsEntity {
    @PrimaryGeneratedColumn('uuid')
    uuid: string;

    @Column()
    name: string;

    @Column()
    description: string;

    @Column({ type: 'timestamp' })
    @CreateDateColumn()
    createdAt: Date;

    @Column({ type: 'timestamp' })
    @UpdateDateColumn()
    updatedAt: Date;

    //Relationships
    @OneToMany(() => ReportsEntity, (report) => report.application)
    reports: ReportsEntity[]
}

但是,当启动时,我从MySQL中得到以下错误:

Data type "Object" in "ReportsEntity.application" is not supported by "mysql" database.

我没有看到我错过了什么或我做错了什么时,审查和比较的文件。

ars1skjm

ars1skjm1#

删除@ManyToOne上面的@PrimaryColumn(),因为它试图创建数据类型为“ApplicationsEntity”的列,mysql不支持该类型
报表实体

@ManyToOne(() => ApplicationsEntity, (application) => application.reports)
    application: ApplicationsEntity

应用程序实体

@OneToMany(() => ReportsEntity, (report) => report.application)
    reports: ReportsEntity[]

相关问题