title: Postgres foreign key on delete constraint
body: <p>Been following the guide on <a href="http://gorm.io/docs/belongs_to.html" rel="nofollow noreferrer">http://gorm.io/docs/belongs_to.html</a> trying to get simple foreign keys setup, however, I can't find any info on using <code>ON CASCADE</code> or <code>ON DELETE</code>. </p>
  
  <p>On <a href="http://doc.gorm.io/database.html#migration" rel="nofollow noreferrer">http://doc.gorm.io/database.html#migration</a> under the <code>Add Foreign Key</code> section it does make use of <code>ON DELETE</code> and <code>ON CASCADE</code>, however when I use this method when inserting I get a fk constraint error. </p>
  
  <p>I'm looking for advice on using the first method ,<code>gorm:"foreignkey:UserRefer"</code>, to also specify <code>ON DELETE</code> or <code>ON CASCADE</code>. Any suggestions?</p>
  
  <p>EDIT #1:
  To show what I mean by error, I'll use this as an example:</p>
  
  <p><strong>Note.go:</strong></p>
  
  <pre><code>type Note struct {
    NoteId              int       `gorm:"primary_key;AUTO_INCREMENT"`
    RecipientId         int       `gorm:"index"`
    Content             string    `gorm:"not null"`
    CreatedAt           time.Time `gorm:"not null"`
    UpdatedAt           time.Time `gorm:"not null"`
  }
  </code></pre>
  
  <p><strong>User.go</strong></p>
  
  <pre><code>type User struct {
    UserId              int       `gorm:"primary_key;AUTO_INCREMENT"`
    Username            string    `gorm:"not null;unique"`
    Email               string    `gorm:"not null;unique"`
    Notes               []Note
    CreatedAt           time.Time `gorm:"not null"`
    UpdatedAt           time.Time `gorm:"not null"`
  }
  </code></pre>
  
  <p><strong>database.go</strong></p>
  
  <pre><code>db.AutoMigrate(&amp;models.User{}, &amp;models.Note{})
  db.Model(&amp;models.Note{}).AddForeignKey("recipient_id", "users(user_id)", "RESTRICT", "RESTRICT")
  
  user := models.User{Username:"test", Email:"test@gmail.com"}
  note := models.Note{RecipientId:user.UserId, Content:"test"}
  
  db.Create(&amp;user)
  db.Create(&amp;note)
  </code></pre>
  
  <p>When the above code is placed in its proper functions, this error is thrown:</p>
  
  <pre><code>(pq: insert or update on table "notes" violates foreign key constraint "notes_recipient_id_users_user_id_foreign") 
  </code></pre>