GORM allows create database constraints with tag, constraints will be created when AutoMigrate or CreateTable with GORM
CHECK Constraint
Create CHECK constraints with tag check
type UserIndex struct { |
Index Constraint
Checkout Database Indexes
Foreign Key Constraint
GORM will creates foreign keys constraints for associations, you can disable this feature during initialization:
db, err := gorm.Open(sqlite.Open("gorm.db"), &gorm.Config{ |
GORM allows you setup FOREIGN KEY constraints’s OnDelete
, OnUpdate
option with tag constraint
, for example:
type User struct { |