flipped-aurora/gin-vue-admin · critical
%s表数据初始化失败!
Error message
%s表数据初始化失败!
What it means
The initAuthority initializer seeds sys_authorities with the default roles (888, 9528, 8881, and its parent 888). The bulk Create failed and was wrapped via errors.Wrapf with the table name. Downstream initializers (menus-authority, Casbin) depend on this data, so the whole init aborts.
Source
Thrown at server/source/system/authority.go:53
}
func (i *initAuthority) InitializerName() string {
return sysModel.SysAuthority{}.TableName()
}
func (i *initAuthority) InitializeData(ctx context.Context) (context.Context, error) {
db, ok := ctx.Value("db").(*gorm.DB)
if !ok {
return ctx, system.ErrMissingDBContext
}
entities := []sysModel.SysAuthority{
{AuthorityId: 888, AuthorityName: "普通用户", ParentId: utils.Pointer[uint](0), DefaultRouter: "dashboard"},
{AuthorityId: 9528, AuthorityName: "测试角色", ParentId: utils.Pointer[uint](0), DefaultRouter: "dashboard"},
{AuthorityId: 8881, AuthorityName: "普通用户子角色", ParentId: utils.Pointer[uint](888), DefaultRouter: "dashboard"},
}
if err := db.Create(&entities).Error; err != nil {
return ctx, errors.Wrapf(err, "%s表数据初始化失败!", sysModel.SysAuthority{}.TableName())
}
next := context.WithValue(ctx, i.InitializerName(), entities)
return next, nil
}
func (i *initAuthority) DataInserted(ctx context.Context) bool {
db, ok := ctx.Value("db").(*gorm.DB)
if !ok {
return false
}
if errors.Is(db.Where("authority_id = ?", "8881").
First(&sysModel.SysAuthority{}).Error, gorm.ErrRecordNotFound) { // 判断是否存在数据
return false
}
return true
}
View on GitHub (pinned to 3136500ef3)
Solutions
- Look at the wrapped cause for the driver-level error (duplicate primary key 888, unknown column, access denied).
- If re-initializing, drop the database or delete existing sys_authorities rows first.
- Ensure AutoMigrate has brought sys_authorities to the current schema before seeding.
- Verify the DB user has INSERT privileges and connectivity is stable.
- Re-run InitDB; on success the roles are stored in the context for later initializers.
Example fix
// before: duplicate primary key on re-init // Error 1062: Duplicate entry '888' for key 'PRIMARY' // after: clean the table before re-seeding DELETE FROM sys_authorities WHERE authority_id IN (888, 9528, 8881); // then re-run /init/initdb
Defensive patterns
Strategy: try-catch
Validate before calling
// detect pre-existing authority rows before seeding
var n int64
db.Model(&sysModel.SysAuthority{}).Count(&n)
if n > 0 { /* already seeded - skip or wipe first */ } Try / catch
if err := initdb(); err != nil {
if strings.Contains(err.Error(), "sys_authorities") {
log.Printf("authority seed failed: %v", errors.Unwrap(err)) // duplicate 888?
}
return err
} Prevention
- Never run initdb twice against the same database
- Delete legacy sys_authorities rows (888/9528/8881) before re-seeding
- Run AutoMigrate to upgrade old schemas first
- Grant the init user INSERT on sys_authorities
When it happens
Trigger: INSERT INTO sys_authorities fails during InitDB - duplicate AuthorityId rows from a previous init, stale table schema, lost connection, or missing INSERT privilege. Because authority_id is the primary key, re-running init on a seeded DB reliably trips this.
Common situations: Re-running initdb on an already-initialized database; upgrading gin-vue-admin over an old sys_authorities schema; DB account without write access; MySQL/PG outage mid-init.
Related errors
- media.FileUploadAndDownload表数据初始化失败!
- sys_apis表数据初始化失败!
- sys_ignore_apis表数据初始化失败!
- sys_positions表数据初始化失败!
- sys_dictionaries表数据初始化失败!
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/55cd928a1b72b49e.
Report an issue: GitHub.