{"record":{"id":"1230428b2f778f9b","repo":"n8n-io/n8n","slug":"provider-connection-type-cannot-be-changed-create","errorCode":null,"errorMessage":"Provider connection type cannot be changed. Create a new connection instead.","messagePattern":"Provider connection type cannot be changed\\. Create a new connection instead\\.","errorType":"exception","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/import/credentials.ts","lineNumber":184,"sourceCode":"\t\tcredential: Partial<CredentialsEntity>,\n\t\tproject: Project,\n\t\tctx: OperationContext,\n\t) {\n\t\t// UsageScope is instance-local state; imports never change it for existing credentials.\n\t\tlet existing: Pick<CredentialsEntity, 'id' | 'type' | 'usageScope'> | null = null;\n\t\tif (credential.id) {\n\t\t\texisting = await transactionManager.findOne(CredentialsEntity, {\n\t\t\t\twhere: { id: credential.id },\n\t\t\t\tselect: ['id', 'usageScope', 'type'],\n\t\t\t});\n\t\t\tif (existing) {\n\t\t\t\tcredential.usageScope = existing.usageScope;\n\t\t\t\tif (\n\t\t\t\t\texisting.usageScope === 'instance' &&\n\t\t\t\t\tcredential.type !== undefined &&\n\t\t\t\t\tcredential.type !== existing.type\n\t\t\t\t) {\n\t\t\t\t\tthrow new UserError(\n\t\t\t\t\t\t'Provider connection type cannot be changed. Create a new connection instead.',\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcredential.usageScope ??= 'project';\n\n\t\tif (credential.usageScope === 'instance') {\n\t\t\tif (\n\t\t\t\tcredential.isGlobal ||\n\t\t\t\tcredential.isResolvable ||\n\t\t\t\tcredential.isManaged ||\n\t\t\t\tcredential.resolvableAllowFallback ||\n\t\t\t\tcredential.resolverId\n\t\t\t) {\n\t\t\t\tthrow new UserError(\n\t\t\t\t\t'Provider connections cannot be global, managed, or dynamically resolved',\n\t\t\t\t);","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/cli/src/commands/import/credentials.ts#L166-L202","documentation":"Thrown by `import:credentials` storeCredential when an existing credential has `usageScope === 'instance'` (a provider connection) and the import payload sets `type` to a different value than the stored type. Instance-scope provider connections are immutable in type — you cannot morph a Slack credential into an HTTP credential by re-importing.","triggerScenarios":"Re-importing a credentials JSON file where a credential with the same ID exists as an instance credential but the JSON's `type` field differs. Common when the JSON was exported from a different credential type or hand-edited.","commonSituations":"Bulk re-import across environments where the credential type drifted; manual JSON edits; importing a backup that was created from a different credential and reusing the ID.","solutions":["Change the import JSON's `type` to match the existing instance credential's type.","Remove the `id` field from the import JSON so a new credential is created instead of updating.","Delete the existing instance credential first, then import."],"exampleFix":"// before — JSON has type: \"httpBasicAuth\" but DB has \"slackApi\"\n// after — match the type, or drop the id\n{ \"id\": \"x\", \"type\": \"slackApi\", \"name\": \"...\" }","handlingStrategy":"validation","validationCode":"// Before importing, confirm the existing instance credential's type matches the import payload\nasync function typeMatches(ds: DataSource, id: string, importType: string): Promise<boolean> {\n  const row = await ds.getRepository('credentials_entity').findOne({ where: { id }, select: ['type', 'usageScope'] });\n  return row?.usageScope !== 'instance' || row.type === importType;\n}\nif (!(await typeMatches(ds, credential.id, credential.type))) {\n  throw new Error('Type mismatch — drop the id or update the JSON type');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never reuse an existing instance credential's id with a different type in import JSON.","Strip the `id` field when importing credentials across environments to force fresh creation."],"tags":["cli","import","credentials","instance-scope","provider-connection","immutability","user-error"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}