{"record":{"id":"30a8d923ef5c2f90","repo":"twentyhq/twenty","slug":"failed-to-create-searchfieldmetadata-row-s-for-wo","errorCode":null,"errorMessage":"Failed to create searchFieldMetadata row(s) for workspace ${workspaceId}","messagePattern":"Failed to create searchFieldMetadata row\\(s\\) for workspace (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/twenty-server/src/database/commands/upgrade-version-command/2-20/2-20-workspace-command-1783529458170-reconcile-search-field-metadata.command.ts","lineNumber":266,"sourceCode":"                flatEntityToDelete: [],\n                flatEntityToUpdate: [],\n              },\n            },\n            workspaceId,\n            applicationUniversalIdentifier,\n          },\n        );\n\n      if (validateAndBuildResult.status === 'fail') {\n        this.logger.error(\n          `Failed to create searchFieldMetadata row(s) for application ${applicationUniversalIdentifier}:\\n${JSON.stringify(\n            validateAndBuildResult,\n            null,\n            2,\n          )}`,\n        );\n\n        throw new Error(\n          `Failed to create searchFieldMetadata row(s) for workspace ${workspaceId}`,\n        );\n      }\n    }\n  }\n\n  private async flushSearchFieldMetadataCacheAndBumpMetadataVersion(\n    workspaceId: string,\n  ): Promise<void> {\n    const searchFieldMetadataRelatedMetadataNames = [\n      'searchFieldMetadata',\n      ...getMetadataRelatedMetadataNames('searchFieldMetadata'),\n      ...getMetadataSerializedRelationNames('searchFieldMetadata'),\n    ] as const;\n    const cacheKeysToFlush = [\n      ...new Set(\n        searchFieldMetadataRelatedMetadataNames.map(getMetadataFlatEntityMapsKey),\n      ),","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-server/src/database/commands/upgrade-version-command/2-20/2-20-workspace-command-1783529458170-reconcile-search-field-metadata.command.ts#L248-L284","documentation":"Thrown by the 2.20 searchFieldMetadata reconciliation command during applyBackfill. For each application missing searchFieldMetadata rows, validateBuildAndRunWorkspaceMigration is called with searchFieldMetadata creation operations. On failure, the detailed report is logged via logger.error, then the generic error is thrown. This pipeline validates, builds, and executes the metadata row creation.","triggerScenarios":"validateBuildAndRunWorkspaceMigration returns status 'fail' when creating searchFieldMetadata flat entities. Caused by: a universal identifier collision with surviving legacy rows (re-own rolled back), the referenced fieldMetadata not existing in the workspace, stale flatSearchFieldMetadataMaps in cache, or a DB error during execution.","commonSituations":"The re-own phase (applyReOwn) transaction rolled back, leaving legacy v4-identifier rows that collide with the deterministic identifiers the backfill tries to create; workspace cache was not flushed after a prior partial run.","solutions":["Check the logger.error JSON output for the specific validation/build errors in the report","Flush flatSearchFieldMetadataMaps from workspace cache and retry — the command is idempotent","Verify the re-own phase committed: query searchFieldMetadataRepository for rows still using legacy universalIdentifier values","Run with --dryRun to inspect the intended operations"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Before running, flush search-field-related cache and verify re-own committed\nawait workspaceCacheService.invalidateAndRecompute(workspaceId, [\n  'flatSearchFieldMetadataMaps',\n  'flatFieldMetadataMaps',\n]);\n\n// Check that no legacy searchFieldMetadata universal identifiers remain\nconst legacyRows = await searchFieldMetadataRepository.count({\n  where: { workspaceId },\n});\n// Compare against expected deterministic identifiers to detect survivors","typeGuard":null,"tryCatchPattern":"// Retry once after flushing cache\ntry {\n  await command.runOnWorkspace({ workspaceId, options: { dryRun: false } });\n} catch (error) {\n  if (error.message.includes('Failed to create searchFieldMetadata row')) {\n    await workspaceCacheService.flush(workspaceId, ['flatSearchFieldMetadataMaps']);\n    await command.runOnWorkspace({ workspaceId, options: { dryRun: false } });\n  } else {\n    throw error;\n  }\n}","preventionTips":["Verify the re-own phase completed before the backfill runs (check for surviving legacy universalIdentifier values)","Run with --dryRun first to inspect planned searchFieldMetadata operations","Flush flatSearchFieldMetadataMaps cache before retrying","Parse the logger.error JSON for the specific builder validation errors"],"tags":["metadata","upgrade-command","workspace-migration","validate-build-run","search-field-metadata"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}