TypeORM 为特定列添加 empty/null 值

TypeORM adding empty/null values for a specific column

问题是有时特定列无缘无故变为空或 null,列为“link_status”,请按照以下代码操作。

“typeorm”:“^0.2.40”

useFactory: async () =>
  await createConnection({
    type: 'mysql',
    host: process.env.DB_HOST,
    port: 3306,
    username: process.env.DB_USER,
    password: process.env.DB_PASS,
    database: process.env.DB_DATABASE,
    entities: [Link, LinkPayment, LinkPaymentStatus, LinkItems],
    synchronize: true,
  }),
@Entity('link')
export class Link extends BaseEntity {
  @PrimaryGeneratedColumn()
  link_id: number
  @Column()
  patient_id: number
  @Column({ length: 9 })
  link_status: string
  @Column({ length: 45 })
  token: string
  @Column({ length: 100 })
  link_url: string
  @Column()
  created_at: Date
  @Column()
  expiry_at: Date
  @Column()
  updated_at: Date
}

问题是当我将我的分支更改为实体中没有该列的版本并且 synchronizetrue 他们将此列中的所有行都变为空,因为该列没有不存在。

一个简单的配置和使用误区...