Product_stone_table
我还试图将计数设置为product_stone表中的{nullable:true},并在创建产品期间添加计数,但是当我想重新启动服务器时,我会收到错误kile:
QueryFailedError: column "count" of relation "product_stone" contains null values
那里有人指导我吗?
product.entity.ts
@Entity()
export class Product extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;
@ManyToMany(() => Stone)
@JoinTable({
name: 'product_stone',
joinColumn: {
name: 'productId',
referencedColumnName: 'id',
},
inverseJoinColumn: {
name: 'stoneId',
referencedColumnName: 'id',
},
})
stones: Stone[];
}
stone.entity.ts
@Entity()
export class Stone extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;
@Column()
title: string;
}
product_stone.entity.ts
@Entity('product_stone')
export class ProductStone extends BaseEntity {
@Column({ nullable: true })
count: number;
@Column()
@IsNotEmpty()
@PrimaryColumn()
productId: number;
@Column()
@IsNotEmpty()
@PrimaryColumn()
stoneId: number;
}
我不认为您可以在多对多桌子上定义自定义属性。 documentation
:在您的情况下,这意味着您必须这样做:
// product.entity.ts
...
@OneToMany(() => ProductToStone, productToStone => productToStone.product)
public productToStones!: ProductToStone[];
// stone.entity.ts ... @OneToMany(() => ProductToStone, productToStone => productToStone.stone) public productToStones!: ProductToStone[];