go-gorm / postgres

GORM PostgreSQL driver
MIT License
234 stars 123 forks source link

Disable add existing constraint #145

Closed crastinus closed 1 year ago

crastinus commented 1 year ago

Disabling add constraint when constraint doesn't present in model but present in the database.

User Case Description

For example run automigrate for this Model

type Values struct {
    Name  string `gorm:"unique"`
    MyVal  bool   
}

  ....

db.Migrator().AutoMigrate(&Values{})

Try again after removing constraint "unique" from Name field

type Values struct {
    Name  string 
    MyVal  bool   
}

  ....

db.Migrator().AutoMigrate(&Values{})

Got errors messages:

ERROR: relation "idx_valuses_name" already exists (SQLSTATE 42P07)