Tencent/WeKnora · error
tenant has associated knowledge bases
Error message
tenant has associated knowledge bases
What it means
Sentinel ErrTenantHasKnowledgeBase returned by the tenant repository when a delete is attempted on a tenant that still owns one or more knowledge bases — a referential-integrity guard preventing orphaned KB data. Not a database error.
Source
Thrown at internal/application/repository/tenant.go:16
package repository
import (
"context"
"errors"
"github.com/Tencent/WeKnora/internal/logger"
"github.com/Tencent/WeKnora/internal/types"
"github.com/Tencent/WeKnora/internal/types/interfaces"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
var (
ErrTenantNotFound = errors.New("tenant not found")
ErrTenantHasKnowledgeBase = errors.New("tenant has associated knowledge bases")
)
// tenantRepository implements tenant repository interface
type tenantRepository struct {
db *gorm.DB
}
// NewTenantRepository creates a new tenant repository
func NewTenantRepository(db *gorm.DB) interfaces.TenantRepository {
return &tenantRepository{db: db}
}
// CreateTenant creates tenant
func (r *tenantRepository) CreateTenant(ctx context.Context, tenant *types.Tenant) error {
return r.db.WithContext(ctx).Create(tenant).Error
}
// GetTenantByID gets tenant by IDView on GitHub (pinned to 988cbb0330)
Solutions
- Delete or reassign the tenant's knowledge bases first, then retry the tenant deletion
- Use a force/cascade delete flow in the service layer if that is the intended policy
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at internal/application/repository/tenant.go:16 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/7bf022b4d20235b3.
Report an issue: GitHub.