mirror of https://github.com/go-gorm/gorm.git
debug
This commit is contained in:
parent
e483cd9993
commit
38fb45fea8
|
@ -759,7 +759,8 @@ func (m Migrator) CreateConstraint(value interface{}, name string) error {
|
||||||
func (m Migrator) DropConstraint(value interface{}, name string) error {
|
func (m Migrator) DropConstraint(value interface{}, name string) error {
|
||||||
return m.RunWithValue(value, func(stmt *gorm.Statement) error {
|
return m.RunWithValue(value, func(stmt *gorm.Statement) error {
|
||||||
if !m.HasConstraint(value, name) {
|
if !m.HasConstraint(value, name) {
|
||||||
return nil
|
constraint, _ := m.GuessConstraintInterfaceAndTable(stmt, name)
|
||||||
|
return errors.New(fmt.Sprintf("Can't find constraint for %q, with guessed name %q", name, constraint))
|
||||||
}
|
}
|
||||||
constraint, table := m.GuessConstraintInterfaceAndTable(stmt, name)
|
constraint, table := m.GuessConstraintInterfaceAndTable(stmt, name)
|
||||||
if constraint != nil {
|
if constraint != nil {
|
||||||
|
|
|
@ -681,6 +681,10 @@ func TestMigrateConstraint(t *testing.T) {
|
||||||
DB.Migrator().CreateConstraint(&User{}, name)
|
DB.Migrator().CreateConstraint(&User{}, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !DB.Migrator().HasConstraint(&User{}, name) {
|
||||||
|
t.Fatalf("failed to create constraint %v", name)
|
||||||
|
}
|
||||||
|
|
||||||
if err := DB.Migrator().DropConstraint(&User{}, name); err != nil {
|
if err := DB.Migrator().DropConstraint(&User{}, name); err != nil {
|
||||||
t.Fatalf("failed to drop constraint %v, got error %v", name, err)
|
t.Fatalf("failed to drop constraint %v, got error %v", name, err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue