查询失败:DROP TABLE

时间:2019-08-22 06:24:44

标签: react-native typeorm

我在我的本机项目中使用Typeorm,我有3个实体,这是我的连接:

connectDb() {
    return createConnection(
      {
        type: "react-native",
        database: "Beita",
        location: "default",
        logging: ["error","query"], 
        synchronize: true,
        entities: [
         CategoryEntity,
         PoemEntity,
         HemistichEntity,  
        ]
      }
    );
  }

如您所知,将synchronize设置为true时,您的实体将在每次运行应用程序时与数据库同步。 为此TypeOrm将删除每个表并重新创建它们。

但是在向表中添加一些数据并重新运行应用程序后,我得到了此错误:

console.error: "query failed: ", "DROP TABLE "PoemEntity""

这些是我的实体:

@Entity("PoemEntity")
export class PoemEntity {
  ...
  @OneToMany(
    type => HemistichEntity,
    hemistichEntity => hemistichEntity.poem,
  )
  hemistichs!: HemistichEntity[];

  @ManyToOne(
    type => CategoryEntity,
    categoryEntity => categoryEntity.poems
  )
  category!: CategoryEntity;

}

@Entity("HemistichEntity")
export class HemistichEntity {
  ...
  @ManyToOne(
    type => PoemEntity,
    poemEntity => poemEntity.hemistichs
  )
  poem!: PoemEntity;
}

@Entity("CategoryEntity")
export class CategoryEntity {
  ...
  @OneToMany(
    type => PoemEntity,
    poemEntity => poemEntity.category
  )
  poems!: PoemEntity[];
}

0 个答案:

没有答案