The long and short of it is that gorm only seems to respect uuid columns if they're primary keys, in all other cases, it creates and/or migrates to text instead.
type UserToken struct {
UUID string `gorm:"primary_key;type:uuid;default:public.uuid_generate_v4()"`
}
results in
Column | Type | Modifiers
--------------------+--------------------------+-------------------------------------
uuid | uuid | not null default uuid_generate_v4()
as you would expect, but
type UserTokenCompany struct {
CompanyGUID string `gorm:"index:idx_company_guid_user_token_uuid,unique"`
UserTokenUUID uuid.UUID `gorm:"index:idx_company_guid_user_token_uuid,unique"`
}
or
type UserTokenCompany struct {
CompanyGUID string `gorm:"index:idx_company_guid_user_token_uuid,unique"`
UserTokenUUID string `gorm:"index:idx_company_guid_user_token_uuid,unique;type:uuid"`
}
both result in Migrator().CreateTable() and AutoMigrate() producing
Column | Type | Modifiers
--------------------------+------+-----------
company_guid | text | not null
user_token_uuid | text | not null
which unsurprisingly breaks joins and foreign keys.
This appears to be the case on both v1.24.1 and v1.24.3.
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨