apache/answer · error

insert site info failed

Error message

insert site info failed: %w

What it means

Fires in the v10 migration addLoginLimitations when the INSERT of the default users site-info row (entity.SiteInfo type SiteTypeUsers) fails against the database. This means the migration could not seed the users site configuration (allow-update flags and default avatar); the wrapped cause is the SQL insert error (e.g. duplicate key, connection loss, schema mismatch).

Solutions

  1. Check the wrapped DB error (duplicate key vs privilege)
  2. Grant INSERT privilege on site_info
  3. Run migrations from a single instance or use a lock to avoid duplicate inserts
  4. Verify site_info schema matches entity.SiteInfo then re-run
Defensive patterns

Strategy: validation

Validate before calling

// pre-check for existing users row to avoid duplicate-key races
has, _ := engine.SQL("SELECT COUNT(*) FROM site_info WHERE type=?", "users").Count()
if has > 0 {
    return fmt.Errorf("users site info already exists; skip seeding")
}

Try / catch

if err := migrations.Migrate(db); err != nil {
    if strings.Contains(err.Error(), "insert site info failed") {
        log.Errorf("could not seed users config (privileges or duplicate): %v", err)
    }
    return err
}

Prevention

When it happens

Trigger: x.Context(ctx).Insert(usersSiteInfo) errors: INSERT privilege denied, duplicate type='users' row inserted concurrently, table/column mismatch, or connection drop.

Common situations: Two migration processes racing to seed the same row; migration user read-only; site_info schema altered manually so required columns are missing.

Related errors


AI-assisted analysis of apache/answer@3b9f137061 (2026-09-05). Data as JSON: /api/errors/dfd87b9a91296e69. Report an issue: GitHub.

Appendix: source

Thrown at internal/migrations/v10.go:87

	}
	if exist {
		siteUsers.DefaultAvatar = gjson.Get(interfaceSiteInfo.Content, "default_avatar").String()
	}
	data, _ := json.Marshal(siteUsers)

	exist, err = x.Context(ctx).Get(&entity.SiteInfo{Type: constant.SiteTypeUsers})
	if err != nil {
		return fmt.Errorf("get config failed: %w", err)
	}
	if !exist {
		usersSiteInfo := &entity.SiteInfo{
			Type:    constant.SiteTypeUsers,
			Content: string(data),
			Status:  1,
		}
		_, err = x.Context(ctx).Insert(usersSiteInfo)
		if err != nil {
			return fmt.Errorf("insert site info failed: %w", err)
		}
	}
	return nil
}

View on GitHub (pinned to 3b9f137061)