I'm having issues with creating foreign key constraint for the Belongs to relationship.
A struct containing foreign key:
type Summary struct { Id string `gorm:"primaryKey"` OwnerId *string `gorm:"foreignKey:OwnerId references:Id;not null"` Title string } Struct to which summary belongs to:
type Owner struct { Id string `gorm:"primaryKey"` Name string } It creates the tables in SQL without a problem but SQL schema doesn't contain foreign key constraint in the summary table on the owner_id column and therefore Summary can be inserted when an owner doesn't exist.