{"record":{"id":"3dc31f9a8bdcbbc2","repo":"twentyhq/twenty","slug":"failed-to-add-coreworkflowid-field-for-workspace","errorCode":null,"errorMessage":"Failed to add coreWorkflowId field for workspace ${workspaceId}","messagePattern":"Failed to add coreWorkflowId field for workspace (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/twenty-server/src/database/commands/upgrade-version-command/2-23/2-23-workspace-command-1784286706000-add-workflow-core-soft-ref-field.command.ts","lineNumber":134,"sourceCode":"          workspaceId,\n          applicationUniversalIdentifier:\n            twentyStandardFlatApplication.universalIdentifier,\n          allFlatEntityOperationByMetadataName: {\n            fieldMetadata: {\n              flatEntityToCreate: [flatFieldMetadataToCreate],\n              flatEntityToDelete: [],\n              flatEntityToUpdate: [],\n            },\n          },\n        },\n      );\n\n    if (result.status === 'fail') {\n      this.logger.error(\n        `Failed to add coreWorkflowId field:\\n${JSON.stringify(result, null, 2)}`,\n      );\n\n      throw new Error(\n        `Failed to add coreWorkflowId field for workspace ${workspaceId}`,\n      );\n    }\n\n    this.logger.log(`Added coreWorkflowId field for workspace ${workspaceId}`);\n  }\n}\n","sourceCodeStart":116,"sourceCodeEnd":142,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-server/src/database/commands/upgrade-version-command/2-23/2-23-workspace-command-1784286706000-add-workflow-core-soft-ref-field.command.ts#L116-L142","documentation":"Thrown by the 2.23 command that adds the coreWorkflowId field, after the standard field was successfully resolved. The command calls validateBuildAndRunLegacyWorkspaceMigration with a fieldMetadata creation operation. If the legacy pipeline returns status 'fail', the result is logged to logger.error and the generic error is thrown.","triggerScenarios":"validateBuildAndRunLegacyWorkspaceMigration returns status 'fail' when creating the coreWorkflowId FlatFieldMetadata. Caused by: the workflow object not existing in workspace metadata at build time, a universal identifier collision, stale flatFieldMetadataMaps cache, or a DB error during column creation.","commonSituations":"Workspace cache reports the field as missing when it exists in the DB; a prior partial run created the DB column but not the metadata row; concurrent workspace modifications during upgrade.","solutions":["Read the logger.error JSON output for the specific failure report","Flush flatFieldMetadataMaps from workspace cache and retry — the command is idempotent","Verify the workflow object exists in flatObjectMetadataMaps","Run with --dryRun to confirm the operation shape"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Before running, flush field metadata cache\nawait workspaceCacheService.invalidateAndRecompute(workspaceId, [\n  'flatFieldMetadataMaps',\n  'flatObjectMetadataMaps',\n]);\n\n// Confirm the workflow object exists\nconst { flatObjectMetadataMaps } = await workspaceCacheService.getOrRecompute(workspaceId, [\n  'flatObjectMetadataMaps',\n]);\n\nconst hasWorkflow = isDefined(\n  flatObjectMetadataMaps.byUniversalIdentifier[STANDARD_OBJECTS.workflow.universalIdentifier]\n);\n\nif (!hasWorkflow) {\n  console.log('workflow object does not exist — command will skip');\n}","typeGuard":null,"tryCatchPattern":"// Retry once after flushing cache — the command is idempotent\ntry {\n  await command.runOnWorkspace({ workspaceId, options: { dryRun: false } });\n} catch (error) {\n  if (error.message.includes('Failed to add coreWorkflowId field')) {\n    await workspaceCacheService.flush(workspaceId, ['flatFieldMetadataMaps']);\n    await command.runOnWorkspace({ workspaceId, options: { dryRun: false } });\n  } else {\n    throw error;\n  }\n}","preventionTips":["Run with --dryRun first to validate the operation shape","Flush flatFieldMetadataMaps cache before retrying — the command is idempotent","Parse the logger.error JSON for the specific validation failure","Ensure no concurrent workspace metadata modifications"],"tags":["metadata","upgrade-command","workspace-migration","validate-build-run","flat-field-metadata","workflow"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}