I want to declare foreign key relation between tables using XORM in golang for postgres.
I've tried the following schema to create foreign key relationship.
type Author struct {
Id uint64 `xorm:"pk autoincr"`
Name string `xorm:"VARCHAR(128) NOT NULL"`
Email string `xorm:"VARCHAR(128) NOT NULL UNIQUE"`
Phone string `xorm:"VARCHAR(32)"`
Age float32
Address string `xorm:"VARCHAR(256)"`
Created time.Time `xorm:"created"`
Updated time.Time `xorm:"updated"`
}
type Book struct {
Id uint64 `xorm:"pk autoincr"`
Name string `xorm:"varchar(128) NOT NULL"`
Isbn string `xorm:"varchar(64) NOT NULL"`
Author *Author `xorm:"-"`
Created time.Time `xorm:"created"`
Updated time.Time `xorm:"updated"`
}
And then,
err := engine.Sync(new(models.Author))
err = engine.Sync(new(models.Book))
But the above code doesn't create foreign key, even no column named author in Book table. Help me to solve this problem that how i can declare foreign key for postgres.