flipped-aurora/gin-vue-admin · error
未找到 %s 表初始化数据
Error message
未找到 %s 表初始化数据
What it means
Thrown by the sys_dictionary_details initializer when the shared init context does not contain the SysDictionary seed data produced by initDict under its InitializerName key. This is a dependency-ordering guard: dictionary details must attach to dictionaries seeded earlier. The wrapped sentinel is system.ErrMissingDependentContext.
Source
Thrown at server/source/system/dictionary_detail.go:48
db, ok := ctx.Value("db").(*gorm.DB)
if !ok {
return false
}
return db.Migrator().HasTable(&sysModel.SysDictionaryDetail{})
}
func (i *initDictDetail) InitializerName() string {
return sysModel.SysDictionaryDetail{}.TableName()
}
func (i *initDictDetail) InitializeData(ctx context.Context) (context.Context, error) {
db, ok := ctx.Value("db").(*gorm.DB)
if !ok {
return ctx, system.ErrMissingDBContext
}
dicts, ok := ctx.Value(new(initDict).InitializerName()).([]sysModel.SysDictionary)
if !ok {
return ctx, errors.Wrap(system.ErrMissingDependentContext,
fmt.Sprintf("未找到 %s 表初始化数据", sysModel.SysDictionary{}.TableName()))
}
True := true
dicts[0].SysDictionaryDetails = []sysModel.SysDictionaryDetail{
{Label: "男", Value: "1", Status: &True, Sort: 1},
{Label: "女", Value: "2", Status: &True, Sort: 2},
}
dicts[1].SysDictionaryDetails = []sysModel.SysDictionaryDetail{
{Label: "smallint", Value: "1", Status: &True, Extend: "mysql", Sort: 1},
{Label: "mediumint", Value: "2", Status: &True, Extend: "mysql", Sort: 2},
{Label: "int", Value: "3", Status: &True, Extend: "mysql", Sort: 3},
{Label: "bigint", Value: "4", Status: &True, Extend: "mysql", Sort: 4},
{Label: "int2", Value: "5", Status: &True, Extend: "pgsql", Sort: 5},
{Label: "int4", Value: "6", Status: &True, Extend: "pgsql", Sort: 6},
{Label: "int6", Value: "7", Status: &True, Extend: "pgsql", Sort: 7},
{Label: "int8", Value: "8", Status: &True, Extend: "pgsql", Sort: 8},
}View on GitHub (pinned to 3136500ef3)
Solutions
- Ensure initDict runs (and succeeds) before initDictDetail in the initializer registration/execution order
- Pass the same ctx through the whole initializer chain instead of constructing a new one per initializer
- Check the return error of the dictionary initializer before calling the detail initializer; fix that first (see sys_dictionaries 表数据初始化失败)
- In custom/test harnesses, populate ctx with context.WithValue(ctx, new(initDict).InitializerName(), []sysModel.SysDictionary{...}) before calling
Example fix
// before: detail init on a fresh context missing dictionary data
ctx, _ = initDictDetail{}.InitializeData(context.WithValue(ctx, "db", db))
// after: run dependent initializers in order on the shared context
ctx, err = initDict{}.InitializeData(ctx)
if err != nil { return err }
ctx, err = initDictDetail{}.InitializeData(ctx) Defensive patterns
Strategy: validation
Validate before calling
dicts, ok := ctx.Value(new(initDict).InitializerName()).([]sysModel.SysDictionary)
if !ok || len(dicts) == 0 {
return errors.New("run initDict initializer before initDictDetail")
} Type guard
func dictionariesInCtx(ctx context.Context) ([]sysModel.SysDictionary, bool) {
dicts, ok := ctx.Value(new(initDict).InitializerName()).([]sysModel.SysDictionary)
return dicts, ok && len(dicts) > 0
} Try / catch
ctx, err = initDictDetail{}.InitializeData(ctx)
if errors.Is(errors.Cause(err), system.ErrMissingDependentContext) {
return fmt.Errorf("初始化顺序错误: %w", err)
} Prevention
- Keep the system initializer order fixed: dependents after their dependencies
- Never construct a fresh context for a single initializer; pass the shared ctx
- Always check and propagate the error from each initializer before the next
- Add an integration test that runs the full initializer chain in order
When it happens
Trigger: Calling initDictDetail.InitializeData(ctx) with a ctx that never passed through initDict.InitializeData, or the earlier initializer stored a non-[]sysModel.SysDictionary value / failed and stored nothing under new(initDict).InitializerName().
Common situations: Reordering the initializer registration list so the detail initializer runs before the dictionary initializer; reusing a fresh context.Value("db")-only context for a single initializer in tests; an earlier dictionary init error swallowed so its result was never placed in the context.
Related errors
- 创建 [用户-权限] 关联失败, 未找到权限表初始化数据
- 创建 [菜单-权限] 关联失败, 未找到权限表初始化数据
- 数据库未初始化
- media.FileUploadAndDownload表数据初始化失败!
- sys_apis表数据初始化失败!
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/c8b159587bdc5d3a.
Report an issue: GitHub.