Skip to content

onetoone relation with flag primayKey:true creates redundant unique contraint #6670

@m-nikhil

Description

@m-nikhil

Issue type:

[X] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[X] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[X] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

@Entity()
export class StationMetric {

  @PrimaryColumn('uuid')
  stationId: string;

  @OneToOne(
      () => Station,
      {primary:true}
  )
  @JoinColumn({name: 'stationId'})
  station: Station
} 

The above code generates the following query:

await queryRunner.query(`CREATE TABLE "station_metric" ("stationId" uuid NOT NULL, CONSTRAINT "REL_58d69669f9e935320b59550430" UNIQUE ("stationId"), CONSTRAINT "PK_58d69669f9e935320b59550430d" PRIMARY KEY ("stationId"))`); 

The Unique constrain in stationId is reductant as its the primary key. I guess its a bug, please confirm. If its a bug, willing to work on a fix for the same :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions