flipped-aurora/gin-vue-admin · error
删除失败!
Error message
删除失败!
What it means
The Delete method removes a SysAutoCodePackage row by ID; this error wraps any GORM error returned by that DELETE. It is a direct database failure (connection, constraint, or SQL error), not a 'not found' condition — GORM does not error when zero rows match.
Source
Thrown at server/service/system/auto_code_package.go:113
if err != nil {
return err
}
}
fmt.Printf("[type:%s]注入成功!\n", key)
}
}
}
return nil
})
}
// Delete 删除包记录
// @author: [piexlmax](https://github.com/piexlmax)
// @author: [SliverHorn](https://github.com/SliverHorn)
func (s *autoCodePackage) Delete(ctx context.Context, info common.GetById) error {
err := global.GVA_DB.WithContext(ctx).Delete(&model.SysAutoCodePackage{}, info.Uint()).Error
if err != nil {
return errors.Wrap(err, "删除失败!")
}
return nil
}
// DeleteByNames
// @author: [piexlmax](https://github.com/piexlmax)
// @author: [SliverHorn](https://github.com/SliverHorn)
func (s *autoCodePackage) DeleteByNames(ctx context.Context, names []string) error {
if len(names) == 0 {
return nil
}
err := global.GVA_DB.WithContext(ctx).Where("package_name IN ?", names).Delete(&model.SysAutoCodePackage{}).Error
if err != nil {
return errors.Wrap(err, "删除失败!")
}
return nil
}
View on GitHub (pinned to 3136500ef3)
Solutions
- Check the wrapped inner error for the underlying DB message (connection refused / table doesn't exist / deadlock)
- Verify global.GVA_DB connectivity and credentials in config
- Run migrations so model.SysAutoCodePackage (sys_auto_code_packages) exists: ensure AutoMigrate covers it
- Retry if the error was a transient lock/timeout
Defensive patterns
Strategy: try-catch
Try / catch
if err := global.GVA_DB.WithContext(ctx).Delete(&model.SysAutoCodePackage{}, info.Uint()).Error; err != nil {
var gormErr gorm.Error
if errors.As(err, &gormErr) {
log.Printf("db delete failed for id %d: %v", info.ID, err)
}
return errors.Wrap(err, "删除失败!")
} Prevention
- Run AutoMigrate for sys_auto_code_packages on startup
- Add DB health checks before batch admin operations
- Retry transient errors (deadlock, lock timeout) with backoff
- Verify record existence first if you need 'not found' semantics (GORM delete of 0 rows returns nil)
When it happens
Trigger: Calling autoCodePackage.Delete with a valid common.GetById while the database is unreachable, the sys_auto_code_packages table does not exist (migration not run), or a DB-level error occurs during the DELETE.
Common situations: Database migrated partially so the table is missing; MySQL/Postgres down or credentials wrong; connection pool exhausted; row locked by a long transaction causing timeout.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/0ee5cbdb2c2c4495.
Report an issue: GitHub.