Nestjs从实体创建mysql表的问题

问题描述 投票:0回答:1

我在更改实体文件并且Nest / TypeOrm重新生成mysql表时遇到问题。它不反映实体文件中的内容

这是我的user.entity.ts

import { BaseEntity, Entity, Column, Unique, PrimaryGeneratedColumn } from "typeorm";

@Entity()
@Unique(['id'])
export class User extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  uid: string;

  @Column()
  name: string;

  @Column()
  surname: string;

  @Column()
  email: string;

  @Column()
  skype: string;

  @Column()
  levelClassDone: boolean;

  @Column({default: 1, nullable: true})
  userType: number;
}

这是在mysql中创建的表的描述:

+----------------+--------------+------+-----+---------+-------+
| Field          | Type         | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+-------+
| name           | varchar(255) | NO   |     | NULL    |       |
| surname        | varchar(255) | NO   |     | NULL    |       |
| email          | varchar(255) | NO   | UNI | NULL    |       |
| uid            | varchar(255) | NO   |     | NULL    |       |
| skype          | varchar(255) | NO   |     | NULL    |       |
| levelClassDone | tinyint      | NO   |     | NULL    |       |
| userType       | int          | YES  |     | 1       |       |
| id             | varchar(255) | NO   | PRI | NULL    |       |
+----------------+--------------+------+-----+---------+-------+

id不是numeric,也不是auto_increment

似乎是在缓存旧的user.entity.ts版本,其中我具有不同的字段规范。我试图删除表,也删除整个数据库。

nest nestjs typeorm
1个回答
0
投票

[将TypeORM导入模块时尝试提供autoLoadEntitiessynchronize选项:

    TypeOrmModule.forRoot({
      autoLoadEntities: true,
      synchronize: true,
      ...
    }
© www.soinside.com 2019 - 2024. All rights reserved.