From 92bc52270eef31212791eea77454eeb5bba71f74 Mon Sep 17 00:00:00 2001 From: Dave Shrewsberry Date: Thu, 1 Aug 2024 13:45:11 -0400 Subject: [PATCH] use IF EXISTS --- migrator/migrator.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/migrator/migrator.go b/migrator/migrator.go index 189a141f..1c15d1ff 100644 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -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 }) }