Closed KiddoV closed 4 months ago
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 ✨
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 ✨
For migrations you could do:
_foreign_keys=false
DisableForeignKeyConstraintWhenMigrating: false
After this your db's schema will be with new foreign keys
For work you should set param _foreign_keys=true
in DSN and all will work fine
GORM Playground Link
N/A
Description
My model:
I used
"github.com/glebarez/sqlite"
for SQlite driverThe problem occurs when referencing
Item.TestFirmware
orItem.WriteFirmware
with the parent tableXDFirmware.FWId
. According to the GORM documentation,DropTable
should "ignore or delete foreign key constraints when dropping": https://gorm.io/docs/migration.html#TablesI encounter the foreign key constraint failure when running
AutoMigrate
.I know that I can use
DisableForeignKeyConstraintWhenMigrating: true
to bypasses the error, but it compromises the logic as it allows the deletion of parent rows, which should be restricted due toOnDelete:RESTRICT
.Not sure if this is expected behavior or a bug. Thanks,