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

[MySQL] - Auto increment without primary #283

Open
pc3b3r opened this issue Jun 22, 2020 · 0 comments
Open

[MySQL] - Auto increment without primary #283

pc3b3r opened this issue Jun 22, 2020 · 0 comments
Labels
bug no known workaround

Comments

@pc3b3r
Copy link
Contributor

pc3b3r commented Jun 22, 2020

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.

@Kononnable Kononnable added the bug no known workaround label Aug 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug no known workaround
Projects
None yet
Development

No branches or pull requests

2 participants