mirror of https://github.com/go-gorm/gorm.git
Add detailed error information when missing table name
This commit is contained in:
parent
a2faa41cbe
commit
dbc6b34dce
|
@ -83,9 +83,13 @@ func (p *processor) Execute(db *DB) {
|
||||||
|
|
||||||
if stmt.Model != nil {
|
if stmt.Model != nil {
|
||||||
if err := stmt.Parse(stmt.Model); err != nil && (!errors.Is(err, schema.ErrUnsupportedDataType) || (stmt.Table == "" && stmt.SQL.Len() == 0)) {
|
if err := stmt.Parse(stmt.Model); err != nil && (!errors.Is(err, schema.ErrUnsupportedDataType) || (stmt.Table == "" && stmt.SQL.Len() == 0)) {
|
||||||
|
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)
|
db.AddError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if stmt.Dest != nil {
|
if stmt.Dest != nil {
|
||||||
stmt.ReflectValue = reflect.ValueOf(stmt.Dest)
|
stmt.ReflectValue = reflect.ValueOf(stmt.Dest)
|
||||||
|
|
|
@ -7,10 +7,10 @@ require (
|
||||||
github.com/jinzhu/now v1.1.1
|
github.com/jinzhu/now v1.1.1
|
||||||
github.com/lib/pq v1.6.0
|
github.com/lib/pq v1.6.0
|
||||||
gorm.io/driver/mysql v1.0.1
|
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/sqlite v1.1.3
|
||||||
gorm.io/driver/sqlserver v1.0.4
|
gorm.io/driver/sqlserver v1.0.4
|
||||||
gorm.io/gorm v1.20.1
|
gorm.io/gorm v1.20.2
|
||||||
)
|
)
|
||||||
|
|
||||||
replace gorm.io/gorm => ../
|
replace gorm.io/gorm => ../
|
||||||
|
|
Loading…
Reference in New Issue