bytebase/bytebase · error
constraint %q not found in table %q
Error message
constraint %q not found in table %q
What it means
wtInstallConstraint installs a table constraint by dispatching on its kind (foreign key, check, primary key, exclude, etc.); if none of the recognized constraint kinds matched, it fails hard with this message saying the constraint obj.name was not found within its parent table obj.parentName. It indicates the constraint entry references a parent table relationship the loader cannot resolve, or a constraint type with no installation branch.
Source
Thrown at backend/plugin/schema/pg/walk_through_loader.go:984
continue
}
return cat.AddConstraint(obj.schema, obj.parentName, catalog.ConstraintDef{
Name: chk.Name,
Type: catalog.ConstraintCheck,
CheckExpr: chk.Expression,
})
}
for _, exc := range tbl.ExcludeConstraints {
if exc.Name != obj.name {
continue
}
return cat.AddConstraint(obj.schema, obj.parentName, catalog.ConstraintDef{
Name: exc.Name,
Type: catalog.ConstraintExclude,
CheckExpr: exc.Expression,
})
}
return errors.Errorf("constraint %q not found in table %q", obj.name, obj.parentName)
}
// ---- pseudo forms ----
func wtPseudoTableStmt(schema, name string, cols []string) *ast.CreateStmt {
items := make([]ast.Node, 0, len(cols))
for _, col := range cols {
if col == "" {
continue
}
items = append(items, &ast.ColumnDef{
Colname: col,
TypeName: wtPseudoTextTypeName(),
})
}
return &ast.CreateStmt{
Relation: &ast.RangeVar{
Schemaname: schema,View on GitHub (pinned to 1870550677)
Solutions
- Check obj.name and obj.parentName; confirm the parent table exists in the dump and is installed before the constraint
- Verify the constraint kind/branch: add a handler for the unsupported constraint type if it is a new variant
- Compare the constraint entry in the source dump against wtInstallConstraint's recognized kinds to see why no branch matched
- Regenerate the dump so the constraint references an existing, known table
Defensive patterns
Strategy: validation
Validate before calling
func constraintParentKnown(obj *wtObjectEntry, tables map[string]bool) bool {
return tables[obj.parentName]
} Try / catch
if err := wtInstallConstraint(cat, obj); err != nil {
if strings.Contains(err.Error(), "not found in table") {
log.Printf("constraint %s on %s unresolvable: %v", obj.name, obj.parentName, err)
return nil
}
return err
} Prevention
- Ensure parent tables are installed before constraints referencing them (topological ordering)
- Regenerate dumps whenever tables are renamed so parentName stays in sync
- Extend wtInstallConstraint with a branch for any new constraint kind in your dumps
- Add a dump lint that verifies every constraint's parentName exists among dumped tables
When it happens
Trigger: wtInstallReal processes a constraint entry whose kind has no corresponding install branch in wtInstallConstraint, or whose parent table name (obj.parentName) does not match any table the loader knows about, so every typed branch (FK/check/PK/exclude) was skipped.
Common situations: Dumps containing constraint types not handled (e.g. unusual exclusion variants); parent table renamed or missing from the dump so parentName resolution fails; constraint entries generated for tables absent from the catalog fixtures.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- failed to get rules from database %q
- failed to get materialized views from database %q
- failed to get function dependency tables from database %q
- failed to get functions from database %q
- failed to get sequences from database %q
AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06).
Data as JSON: /api/errors/0764da2db36b7c62.
Report an issue: GitHub.