Skip to content

FK/PK naming strategy or name override question #3847

@zelid

Description

@zelid

Issue type:

[x] question
[ ] 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:

I have some custom UI logic which takes into consideration names of foreign keys.
TypeORM automatically gives random FK names like FkC6Cc2C34Bd5420Cf0F3Fe38695D which seems to be different after each DB re-creation and similar way for PKs like Pk51F365875Ce04758B07Bc160204.

Having for example

@Entity()
export class WebsiteEmail {
  @PrimaryGeneratedColumn()
  id: number

  @ManyToOne(type => Website)
  @JoinColumn()
  website: Website
  @RelationId((self: WebsiteEmail) => self.website)
  websiteId: number

  @Column()
  address: string
}

I'm interested in both FK/PK naming strategy and manual FK/PK name override. Reading documentation showed only JoinColumn name overrides or I've missed the part about FK/PK names...

How to specify FK name for website: Website to be fk_website_email_website_id and PK name for id: number to be pk_website_email_id ?

update 1:
There is some givenName property in the source code. Not sure how to pass there a value from attributes yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions