Is there options to create a foreign key using automigrate?
This issue has been automatically marked as stale as it missing playground pull request link, checkout https://github.com/go-gorm/playground for details, it will be closed in 2 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 ✨
@jinzhu the link doesn't say much. What if you don't want to use the automatic foreign key creation (using an embedded struct) and you want to add one manually like in V1?
// gorm v1
db.AutoMigrate(&TableA{}, &TableB{})
db.Model(TableAB{}).
AddForeignKey("a_id", "table_a(id)", "CASCADE", "CASCADE").
AddForeignKey("b_id", "table_b(id)", "CASCADE", "CASCADE")
@jinzhu Are you going to answer the question or at least update the docs to provide a bit more specificity on the matter. Also can this issue be reopened as it does not look like it has been fully resolved?
This is already supported in V2.
This is already supported in V2.
@jinzhu What does "this" refer to in this sentence? Can you do AddForeignKey in v2? I do not think so. Are there some docs or examples that provide a bit more extensive info on how to setup FKs in V2?
Most helpful comment
@jinzhu What does "this" refer to in this sentence? Can you do
AddForeignKeyin v2? I do not think so. Are there some docs or examples that provide a bit more extensive info on how to setup FKs in V2?