twentyhq/twenty · error · Error
Failed to create searchFieldMetadata row(s) for workspace ${
Error message
Failed to create searchFieldMetadata row(s) for workspace ${workspaceId} What it means
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.
Source
Thrown at packages/twenty-server/src/database/commands/upgrade-version-command/2-20/2-20-workspace-command-1783529458170-reconcile-search-field-metadata.command.ts:266
flatEntityToDelete: [],
flatEntityToUpdate: [],
},
},
workspaceId,
applicationUniversalIdentifier,
},
);
if (validateAndBuildResult.status === 'fail') {
this.logger.error(
`Failed to create searchFieldMetadata row(s) for application ${applicationUniversalIdentifier}:\n${JSON.stringify(
validateAndBuildResult,
null,
2,
)}`,
);
throw new Error(
`Failed to create searchFieldMetadata row(s) for workspace ${workspaceId}`,
);
}
}
}
private async flushSearchFieldMetadataCacheAndBumpMetadataVersion(
workspaceId: string,
): Promise<void> {
const searchFieldMetadataRelatedMetadataNames = [
'searchFieldMetadata',
...getMetadataRelatedMetadataNames('searchFieldMetadata'),
...getMetadataSerializedRelationNames('searchFieldMetadata'),
] as const;
const cacheKeysToFlush = [
...new Set(
searchFieldMetadataRelatedMetadataNames.map(getMetadataFlatEntityMapsKey),
),View on GitHub (pinned to 1f5dd2bbd2)
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
Defensive patterns
Strategy: retry
Validate before calling
// Before running, flush search-field-related cache and verify re-own committed
await workspaceCacheService.invalidateAndRecompute(workspaceId, [
'flatSearchFieldMetadataMaps',
'flatFieldMetadataMaps',
]);
// Check that no legacy searchFieldMetadata universal identifiers remain
const legacyRows = await searchFieldMetadataRepository.count({
where: { workspaceId },
});
// Compare against expected deterministic identifiers to detect survivors Try / catch
// Retry once after flushing cache
try {
await command.runOnWorkspace({ workspaceId, options: { dryRun: false } });
} catch (error) {
if (error.message.includes('Failed to create searchFieldMetadata row')) {
await workspaceCacheService.flush(workspaceId, ['flatSearchFieldMetadataMaps']);
await command.runOnWorkspace({ workspaceId, options: { dryRun: false } });
} else {
throw error;
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to create searchVector GIN index(es) for workspace ${
- Failed to backfill imageIdentifierFieldMetadataId for worksp
- Failed to add coreWorkflowVersionId field for workspace ${wo
- Failed to add coreWorkflowId field for workspace ${workspace
- Failed to fix "Go to Roles Settings" command menu item path
AI-assisted analysis of twentyhq/twenty@1f5dd2bbd2 (2026-08-12).
Data as JSON: /api/errors/30a8d923ef5c2f90.
Report an issue: GitHub.