{"record":{"id":"a986d4647c8372ab","repo":"flipped-aurora/gin-vue-admin","slug":"sys-apis","errorCode":null,"errorMessage":"sys_apis表数据初始化失败!","messagePattern":"sys_apis表数据初始化失败!","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"server/source/system/api.go","lineNumber":254,"sourceCode":"\t\t{ApiGroup: \"参数管理\", Method: \"DELETE\", Path: \"/sysParams/deleteSysParamsByIds\", Description: \"批量删除参数\"},\n\t\t{ApiGroup: \"参数管理\", Method: \"PUT\", Path: \"/sysParams/updateSysParams\", Description: \"更新参数\"},\n\t\t{ApiGroup: \"参数管理\", Method: \"GET\", Path: \"/sysParams/findSysParams\", Description: \"根据ID获取参数\"},\n\t\t{ApiGroup: \"参数管理\", Method: \"GET\", Path: \"/sysParams/getSysParamsList\", Description: \"获取参数列表\"},\n\t\t{ApiGroup: \"参数管理\", Method: \"GET\", Path: \"/sysParams/getSysParam\", Description: \"获取参数列表\"},\n\t\t{ApiGroup: \"媒体库分类\", Method: \"GET\", Path: \"/attachmentCategory/getCategoryList\", Description: \"分类列表\"},\n\t\t{ApiGroup: \"媒体库分类\", Method: \"POST\", Path: \"/attachmentCategory/addCategory\", Description: \"添加/编辑分类\"},\n\t\t{ApiGroup: \"媒体库分类\", Method: \"POST\", Path: \"/attachmentCategory/deleteCategory\", Description: \"删除分类\"},\n\n\t\t{ApiGroup: \"版本控制\", Method: \"GET\", Path: \"/sysVersion/findSysVersion\", Description: \"获取单一版本\"},\n\t\t{ApiGroup: \"版本控制\", Method: \"GET\", Path: \"/sysVersion/getSysVersionList\", Description: \"获取版本列表\"},\n\t\t{ApiGroup: \"版本控制\", Method: \"GET\", Path: \"/sysVersion/downloadVersionJson\", Description: \"下载版本json\"},\n\t\t{ApiGroup: \"版本控制\", Method: \"POST\", Path: \"/sysVersion/exportVersion\", Description: \"创建版本\"},\n\t\t{ApiGroup: \"版本控制\", Method: \"POST\", Path: \"/sysVersion/importVersion\", Description: \"同步版本\"},\n\t\t{ApiGroup: \"版本控制\", Method: \"DELETE\", Path: \"/sysVersion/deleteSysVersion\", Description: \"删除版本\"},\n\t\t{ApiGroup: \"版本控制\", Method: \"DELETE\", Path: \"/sysVersion/deleteSysVersionByIds\", Description: \"批量删除版本\"},\n\t}\n\tif err := db.Create(&entities).Error; err != nil {\n\t\treturn ctx, errors.Wrap(err, sysModel.SysApi{}.TableName()+\"表数据初始化失败!\")\n\t}\n\tnext := context.WithValue(ctx, i.InitializerName(), entities)\n\treturn next, nil\n}\n\nfunc (i *initApi) DataInserted(ctx context.Context) bool {\n\tdb, ok := ctx.Value(\"db\").(*gorm.DB)\n\tif !ok {\n\t\treturn false\n\t}\n\tif errors.Is(db.Where(\"path = ? AND method = ?\", \"/authorityBtn/canRemoveAuthorityBtn\", \"POST\").\n\t\tFirst(&sysModel.SysApi{}).Error, gorm.ErrRecordNotFound) {\n\t\treturn false\n\t}\n\treturn true\n}\n","sourceCodeStart":236,"sourceCodeEnd":271,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/source/system/api.go#L236-L271","documentation":"During gin-vue-admin's database initialization, the initApi initializer bulk-inserts the seeded sys_apis rows (the full API registry used by Casbin/menu binding). The GORM Create call failed, and pkg/errors.Wrap attached this message to the underlying DB error. Without these rows the API management page and permission binding have no data.","triggerScenarios":"Running InitDB (first-time install or re-initialization) when the INSERT into sys_apis fails - e.g. the table exists with conflicting rows (duplicate primary keys), the DB connection drops mid-init, the table schema is stale (missing columns added in a newer version), or the DB user lacks INSERT privilege.","commonSituations":"Re-running init on a partially initialized database where old sys_apis rows remain; upgrading gin-vue-admin against an old schema that was never migrated; MySQL/PG credentials without write access; disk-full or connection-timeout during init.","solutions":["Check the wrapped cause in the logs for the real driver error (duplicate key, unknown column, access denied).","If re-initializing, drop the database (or truncate sys_apis) so the seed insert starts clean.","Verify sys_apis schema matches the current version; let GORM AutoMigrate recreate it during init.","Confirm the configured DB user has INSERT privilege and the server is reachable/has disk space.","Re-run InitDB after fixing; success is silent (returns next context)."],"exampleFix":"// before: init fails on leftover rows\n// duplicate Path+Method unique conflicts on re-init\n// after: wipe the target database (or table) before re-running initdb\nDROP DATABASE gva;\nCREATE DATABASE gva;\n// then POST /init/initdb again","handlingStrategy":"try-catch","validationCode":"// before calling initdb, check DB is reachable and sys_apis is empty\nrows, err := db.Exec(\"SELECT COUNT(*) FROM sys_apis\")\nif err != nil { /* table missing or DB unreachable - fix before init */ }","typeGuard":null,"tryCatchPattern":"if err := initdb(); err != nil {\n    var wrapped interface{ Unwrap() error }\n    if errors.As(err, &cause) {\n        log.Printf(\"sys_apis seed failed: %v\", cause) // duplicate key / schema / privilege\n    }\n    return fmt.Errorf(\"init aborted: %w\", err)\n}","preventionTips":["Always init against a fresh/empty database","Run AutoMigrate so the schema matches the current version before seeding","Use a DB user with CREATE/INSERT privileges","Check the wrapped cause, not just the wrapper message"],"tags":["database","gorm","seed-data","initialization"],"backgroundTag":"db-seed-insert-failed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}