go-gorm / gorm

The fantastic ORM library for Golang, aims to be developer friendly
https://gorm.io
MIT License
37.02k stars 3.94k forks source link

Wrong Foreign Key AutoMigrate default value #7191

Open devhaozi opened 2 months ago

devhaozi commented 2 months ago

GORM Playground Link

https://github.com/go-gorm/playground/pull/758

Description

I'm using a Postgres database with primary key default values of generated by default as identity. There are 2 issues here:

  1. If the primary key is used as a foreign key, then the foreign key field will also have a default value of generated by default as identity.
  2. The primary key type is not bigint as specified by type:.

Below is a screenshot of the playground CI running: image

Related issues: #5222 #5534 (they were missing the playground link, so I opened this)

Expected behavior

  1. ID The ID field correctly use the type: tag, bigint type and generated by default as identity.
  2. Referenced foreign keys should not use the parent key's type: tag.