Foreign key for "uc_work_order" is missing on "uc_work_order_images"

错误:

throw new Error("Foreign key for \"" + relatedClass.name + "\" is missing " +
Error: Foreign key for "uc_work_order" is missing on "uc_work_order_images".

解决方案

正确的表结构说明:

  1. uc_work_order_images 的外键work_order_id 只能选择 uc_work_order.id 和 v_uc_work_order.id 中的一个。
  2. uc_work_order_images的@BelongsTo需要增加参数 work_order_id(ForeignKey):
@BelongsTo(() => v_uc_work_order, "work_order_id")

1. uc_work_order

@Table({
    tableName: 'uc_work_order'
})
export default class uc_work_order extends base_table {
    @Column
    name:string;
}

2. v_uc_work_order

@Table({
    tableName: 'v_uc_work_order'
})
export default class v_uc_work_order extends base_table {
    @Column
    name:string;

    @HasMany(() => uc_work_order_images)
    uc_work_order_images:uc_work_order_images[];
}

3. uc_work_order_images

@Table({
    tableName: 'uc_work_order_images'
})
export default class uc_work_order_images extends base_table {
    @ForeignKey(() => v_uc_work_order)
    @Column
    work_order_id:number;

    @BelongsTo(() => v_uc_work_order, "work_order_id")
    uc_work_order:uc_work_order;

    @Column
    name:string;

    @Column
    url:string;

    @Column
    create_time:Date;
}

你可能感兴趣的:(Foreign key for "uc_work_order" is missing on "uc_work_order_images")