Open alicewenli opened 2 years ago
same problem
You can use autoincrement
, gorm
will convert it to a serial
which is old implementation in postgres.
Maybe we should support it, but it doesn't belong to the tag type
ALTER [ COLUMN ] column_name ADD GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( sequence_options ) ]
Your Question
Is there a way to prevent foreign keys from copying over the default value of its reference?
In the docs, it says:
I'm using a Postgres database with primary key default values of
generated by default as identity
. However, if the primary key is used as a foreign key, then the foreign key field will also have a default value ofgenerated by default as identity
. I don't think this is useful and also results in an extra sequence being created.Example:
The above schema results in tables like:
The
profiles_user_id_seq
is unnecessary, and so is the default value for theuser_id
column in theprofiles
table.The document you expected this should be explained
https://gorm.io/docs/has_one.html#Override-Foreign-Key
Expected answer