Skip to content
This repository was archived by the owner on Oct 10, 2022. It is now read-only.
This repository was archived by the owner on Oct 10, 2022. It is now read-only.

[MySQL] - Auto increment without primary #283

@pc3b3r

Description

@pc3b3r

Considering the following DDL

CREATE TABLE `data` (
  `id` int(10) unsigned NOT NULL DEFAULT '0',
  `ai` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `pk` char(32) NOT NULL,
  PRIMARY KEY (`pk`),
  KEY (`ai`)
)

The generated model is

@Index('ai', ['ai'], {})
@Entity('data', { schema: 'test' })
export class data {
  @Column('int', { name: 'id', unsigned: true, default: () => "'0'" })
  id: number;

  @PrimaryGeneratedColumn({ type: 'int', name: 'ai', unsigned: true })
  ai: number;

  @Column('char', { primary: true, name: 'pk', length: 32 })
  pk: string;
}

In this case ai isn't the Primary Key. It should be checked before applying @PrimaryGeneratedColumn decorator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugno known workaround

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions