|
nestJs中使用typeORM报'QueryFailedError: Table 'equtype' already exists'错误
如图,博主在定义实体类的时候,代码如下- import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn } from 'typeorm';
- import { ApiProperty } from '@nestjs/swagger';
- /**
- * 健身器材类型实体
- */
- @Entity('equType')
- export class Equtype {
- @ApiProperty({ description: 'id' })
- @PrimaryGeneratedColumn('uuid')
- id: string;
- @ApiProperty({ description: '类型名称' })
- @Column({ length: 255 })
- name: string;
- @ApiProperty({ description: '类型描述' })
- @Column({ length: 999 })
- scr: string;
- @ApiProperty({ description: '状态:0-未启用,1-启用' })
- @Column({ type: "enum", enum: [0, 1], default: 1 })
- status: number;
- @CreateDateColumn()
- add_time: Date
- }
复制代码 并将该实体注入到DataSource的entity中:- export const AppDataSource = new DataSource({
- type: 'mysql',
- host: 'localhost',
- port: 3306,
- username: 'root',
- password: 'root',
- database: 'lybs-jdweb',
- // charset: 'utf8mb4',
- timezone: '+08:00',
- synchronize: true, // 是否同步,如果为true,新建的实体会更新建表或更新字段
- logging: false, // 是否开启日志,为true 为打印执行的sql
- entities: [Admin, Role, Buildequ, Equtype], // 数据表实体
- });
复制代码 并重启项目,这时就会存在如上图所示的错误,我画了半个小时解决了该问题:
后来我发现我在定义实体的时候- import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn } from 'typeorm';
- import { ApiProperty } from '@nestjs/swagger';
- @entity('equType')
- export class Equtype {
- @ApiProperty({ description: 'id' })
- @PrimaryGeneratedColumn('uuid')
- id: string;
- @ApiProperty({ description: '类型名称' })
- @column({ length: 255 })
- name: string;
- @ApiProperty({ description: '类型描述' })
- @column({ length: 999 })
- scr: string;
- @ApiProperty({ description: '状态:0-未启用,1-启用' })
- @column({ type: "enum", enum: [0, 1], default: 1 })
- status: number;
- @CreateDateColumn()
- add_time: Date
- }
复制代码 在@entity里注册使用了驼峰命名,我后来将其改成小写就解决了该问题,希望对你有所帮助!- before:
- @Entity('equType')
- after:
- @Entity('equtype')
复制代码 来源:https://www.cnblogs.com/liyublogs/p/17160237.html
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作! |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|