Skip to content

Commit

Permalink
Add stmt.Schema check
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Jul 13, 2021
1 parent 6f50b1d commit 2506248
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ func (m Migrator) DropTable(values ...interface{}) error {
func (m Migrator) HasColumn(value interface{}, name string) bool {
var count int
m.Migrator.RunWithValue(value, func(stmt *gorm.Statement) error {
if field := stmt.Schema.LookUpField(name); field != nil {
name = field.DBName
if stmt.Schema != nil {
if field := stmt.Schema.LookUpField(name); field != nil {
name = field.DBName
}
}

if name != "" {
Expand Down

0 comments on commit 2506248

Please sign in to comment.