{"record":{"id":"dda2a9c78a8813d4","repo":"n8n-io/n8n","slug":"the-credential-with-id-workflow-id-is-already","errorCode":null,"errorMessage":"The credential with ID \"${workflow.id}\" is already owned by ${currentOwner}. It can't be re-owned by ${newOwner}.","messagePattern":"The credential with ID \"(.+?)\" is already owned by (.+?)\\. It can't be re-owned by (.+?)\\.","errorType":"exception","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/import/workflow.ts","lineNumber":146,"sourceCode":"\t\t\tthrow new UserError(\n\t\t\t\t'You cannot use `--userId` and `--projectId` together. Use one or the other.',\n\t\t\t);\n\t\t}\n\n\t\tconst project = await this.getProject(flags.userId, flags.projectId);\n\n\t\tconst ownerUser = await Container.get(UserRepository).findOneByOrFail({\n\t\t\trole: { slug: GLOBAL_OWNER_ROLE.slug },\n\t\t});\n\t\t// This userId will be used as the actor for publish/unpublish workflow actions\n\t\tconst userId = flags.userId ?? ownerUser.id;\n\n\t\tconst workflows = await this.readWorkflows(flags.input, flags.separate);\n\n\t\tconst result = await this.checkRelations(workflows, flags.projectId, flags.userId);\n\n\t\tif (!result.success) {\n\t\t\tthrow new UserError(result.message);\n\t\t}\n\n\t\tthis.logger.info(`Importing ${workflows.length} workflows...`);\n\n\t\tawait Container.get(ImportService).importWorkflows(workflows, project.id, userId, {\n\t\t\tactiveState: flags.activeState,\n\t\t});\n\n\t\tthis.reportSuccess(workflows.length);\n\n\t\tContainer.get(EventService).emit('server-cli-import', {\n\t\t\tactiveState: flags.activeState,\n\t\t\tworkflowCount: workflows.length,\n\t\t\tseparate: flags.separate,\n\t\t});\n\t}\n\n\tprivate async checkRelations(workflows: IWorkflowBase[], projectId?: string, userId?: string) {","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/cli/src/commands/import/workflow.ts#L128-L164","documentation":"Thrown by `import:workflow` (workflow.ts:146) via `throw new UserError(result.message)` where result comes from checkRelations. The message is built at workflow.ts:197 and says 'credential' even though this is the workflow import path — a copy-paste artefact: the workflow already exists in the DB and is owned by a different project/user than the one being imported into. Re-assignment of ownership is blocked to prevent silently moving workflows between projects.","triggerScenarios":"`n8n import:workflow --input=f.json --projectId=B` where the JSON contains a workflow with an ID that already exists and is currently owned by project A (or user A's personal project). checkRelations at workflow.ts:164-206 detects the ownership mismatch.","commonSituations":"Re-importing a backup into a different project; migrating workflows between environments where IDs collide; importing the same file twice with different --projectId flags.","solutions":["Import into the project that already owns the workflow: match --projectId to the current owner.","Remove the `id` field from the import JSON so a fresh workflow is created.","Delete the existing workflow first, then import.","Drop --userId/--projectId entirely to fall back to the original owner."],"exampleFix":"// before — workflow id 'X' owned by project A, importing into project B\nn8n import:workflow --input=f.json --projectId=B\n// after — let n8n create a new workflow instead\n// edit f.json to remove \"id\": \"X\", then:\nn8n import:workflow --input=f.json --projectId=B","handlingStrategy":"validation","validationCode":"async function workflowOwnershipMatches(ds: DataSource, workflowId: string, targetProjectId?: string): Promise<boolean> {\n  if (!targetProjectId) return true;\n  const sharing = await ds.getRepository('shared_workflow').findOne({ where: { workflowId, role: 'workflow:owner' } });\n  return sharing?.projectId === targetProjectId;\n}\nfor (const w of workflows) {\n  if (w.id && !(await workflowOwnershipMatches(ds, w.id, flags.projectId))) {\n    throw new Error(`Workflow ${w.id} already owned elsewhere — remove id or change target`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Strip the `id` field from import JSON when moving workflows between projects.","Import into the project that already owns each workflow ID.","In CI, delete-then-import to avoid ownership collisions."],"tags":["cli","import","workflow","ownership","conflict","user-error"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}