Description
Using 2 separate apps, within a monorepo, I connect through GORM to the same Postgres DB with different DB users into different schemas.
- In the first app I have the
Usermodel withschema1.Userstable - In the 2nd I have the
Taskmodel withschema2.Taskstable
type User struct {
gorm.Model
}
type Task struct {
gorm.Model
CreatedBy uint
User User `gorm:"foreignKey:CreatedBy;references:User"`
}
When I try to run the 2nd API, the migrations create a Users table in schema2 and connects the foreign key there.
If I use the struct below I get an error
type Task struct {
gorm.Model
CreatedBy uint
User User `gorm:"foreignKey:CreatedBy;references:schema1.User"`
}
[error] invalid field found for struct github.com/xyz/models.Tasks's field User: define a valid foreign key for relations or implement the Valuer/Scanner interface
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 ✨