{"record":{"id":"0764da2db36b7c62","repo":"bytebase/bytebase","slug":"constraint-q-not-found-in-table-q","errorCode":null,"errorMessage":"constraint %q not found in table %q","messagePattern":"constraint %q not found in table %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/plugin/schema/pg/walk_through_loader.go","lineNumber":984,"sourceCode":"\t\t\tcontinue\n\t\t}\n\t\treturn cat.AddConstraint(obj.schema, obj.parentName, catalog.ConstraintDef{\n\t\t\tName:      chk.Name,\n\t\t\tType:      catalog.ConstraintCheck,\n\t\t\tCheckExpr: chk.Expression,\n\t\t})\n\t}\n\tfor _, exc := range tbl.ExcludeConstraints {\n\t\tif exc.Name != obj.name {\n\t\t\tcontinue\n\t\t}\n\t\treturn cat.AddConstraint(obj.schema, obj.parentName, catalog.ConstraintDef{\n\t\t\tName:      exc.Name,\n\t\t\tType:      catalog.ConstraintExclude,\n\t\t\tCheckExpr: exc.Expression,\n\t\t})\n\t}\n\treturn errors.Errorf(\"constraint %q not found in table %q\", obj.name, obj.parentName)\n}\n\n// ---- pseudo forms ----\n\nfunc wtPseudoTableStmt(schema, name string, cols []string) *ast.CreateStmt {\n\titems := make([]ast.Node, 0, len(cols))\n\tfor _, col := range cols {\n\t\tif col == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\titems = append(items, &ast.ColumnDef{\n\t\t\tColname:  col,\n\t\t\tTypeName: wtPseudoTextTypeName(),\n\t\t})\n\t}\n\treturn &ast.CreateStmt{\n\t\tRelation: &ast.RangeVar{\n\t\t\tSchemaname:     schema,","sourceCodeStart":966,"sourceCodeEnd":1002,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/plugin/schema/pg/walk_through_loader.go#L966-L1002","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"func constraintParentKnown(obj *wtObjectEntry, tables map[string]bool) bool {\n\treturn tables[obj.parentName]\n}","typeGuard":null,"tryCatchPattern":"if err := wtInstallConstraint(cat, obj); err != nil {\n\tif strings.Contains(err.Error(), \"not found in table\") {\n\t\tlog.Printf(\"constraint %s on %s unresolvable: %v\", obj.name, obj.parentName, err)\n\t\treturn nil\n\t}\n\treturn err\n}","preventionTips":["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"],"tags":["postgres","constraint","catalog","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}