use IF EXISTS

This commit is contained in:
Dave Shrewsberry 2024-08-01 13:45:11 -04:00
parent 4a50b36f63
commit 92bc52270e
1 changed files with 2 additions and 1 deletions

View File

@ -762,7 +762,8 @@ func (m Migrator) DropConstraint(value interface{}, name string) error {
if constraint != nil {
name = constraint.GetName()
}
return m.DB.Exec("ALTER TABLE ? DROP CONSTRAINT ?", clause.Table{Name: table}, clause.Column{Name: name}).Error
// using IF EXISTS here as we are "guessing" the constraint name
return m.DB.Exec("ALTER TABLE ? DROP CONSTRAINT IF EXISTS ?", clause.Table{Name: table}, clause.Column{Name: name}).Error
})
}