There are 2 structures
type Student struct { Id uint64 `sql:"AUTO_INCREMENT" gorm:"primary_key"` Name string `sql:"size:80` } type Struct1 struct { Id uint64 `sql:"AUTO_INCREMENT" gorm:"primary_key"` StudentId Student //`gorm:"ForeignKey:Id"` Time time.Time `sql:"DEFAULT:current_timestamp"` Value int //ΠΠ°ΠΊΠΈΠ΅-Π½ΠΈΠ±ΡΠ΄Ρ Π·Π½Π°ΡΠ΅Π½ΠΈΡ } I did the migration and the tables were created in the database
db.AutoMigrate(&Student{}) db.AutoMigrate(&Struct1{}) But I want, that in a DB communications with cascade change too were created.
That is, now I have added student id 1, and the other table does not know about the existence of the Students table and you can write anything to StudentId.
How to register keys through gorm?
go,IDused instead ofId. But this, I am. - Ivan BlackStudentIDmust be an integer, and the reference to the structure is done separately. Type pastebin - Ivan Black@"ΠΌΠΎΠΉ Π½ΠΈΠΊ", not commenting on my posts, so that I could see the comment. - Ivan Black