forked from mirror/gorm
Add detailed error information when missing table name
This commit is contained in:
parent
a2faa41cbe
commit
dbc6b34dce
|
@ -83,7 +83,11 @@ func (p *processor) Execute(db *DB) {
|
|||
|
||||
if stmt.Model != nil {
|
||||
if err := stmt.Parse(stmt.Model); err != nil && (!errors.Is(err, schema.ErrUnsupportedDataType) || (stmt.Table == "" && stmt.SQL.Len() == 0)) {
|
||||
db.AddError(err)
|
||||
if errors.Is(err, schema.ErrUnsupportedDataType) && stmt.Table == "" {
|
||||
db.AddError(fmt.Errorf("%w: Table not set, please set it like: db.Model(&user) or db.Table(\"users\")", err))
|
||||
} else {
|
||||
db.AddError(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,10 +7,10 @@ require (
|
|||
github.com/jinzhu/now v1.1.1
|
||||
github.com/lib/pq v1.6.0
|
||||
gorm.io/driver/mysql v1.0.1
|
||||
gorm.io/driver/postgres v1.0.1
|
||||
gorm.io/driver/postgres v1.0.2
|
||||
gorm.io/driver/sqlite v1.1.3
|
||||
gorm.io/driver/sqlserver v1.0.4
|
||||
gorm.io/gorm v1.20.1
|
||||
gorm.io/gorm v1.20.2
|
||||
)
|
||||
|
||||
replace gorm.io/gorm => ../
|
||||
|
|
Loading…
Reference in New Issue