Overwriting Existing Credentials IDs with import:credentials

Hey n8n Community,

From my understanding of the CLI import:credentials command documentation, when importing JSON credentials files, if the credential’s ID is specified, then it will be inserted into credentials_entity with such ID. If the ID exists in the table, its row will be overwritten.

From the docs:

However, I was not able to reproduce such behavior. Instead, the ID is always auto-incremented by the database regardless of the ID defined in the credential’s JSON.

Shouldn’t the credential be inserted in the database with the same ID in the JSON file?

If not, how can I prevent workflows from breaking due to this ID change?


Suppose credentials_entity is empty:

database=# select id, name from n8n_credentials_entity;
 id | name 

And I have an exported credential JSON file:

n8n # cat /var/credentials/mysql.json 
  "id": 1,
  "name": "mysql",
  "data": "<encripted-data>",
  "type": "mySql",
  "nodesAccess": [
    { "nodeType": "n8n-nodes-base.mySql", "date": "2022-09-02T19:29:00.552Z" }
  "createdAt": "2022-09-02T19:29:00.561Z",
  "updatedAt": "2022-09-02T19:30:14.370Z"

Then I import this credential into N8N:

N8N # n8n import:credentials --separate --input=/var/credentials/
Successfully imported 1 credential.

When searching for the credential in credentials_entity, it was not added with ID 1, but simply used the next auto-incremented ID:

database=# select id, name from n8n_credentials_entity;
 id | name  
 58 | MySQL

As a consequence, workflows referencing the ID of the JSON file break because they failed to find the credential with such ID.

Thanks in advance.

n8n setup

  • Version: 0.189.1
  • Database: Postgres
  • Running n8n with the execution process: Own (exec n8n start)
  • Running n8n via: Docker
  • Other: Credentials files are mounted from the host via Docker volume bind mount.

Hey @sitio-couto,

Welcome to the community :raised_hands:

I suspect the issue here could be that we update the credential, in your case there appears to be no credential to update so it is creating a new one.

If you have a credential with an ID that matches is it correctly updating it?

Hey @Jon,

Thanks for the warm welcome. Loving n8n so far! :smile:

Yes. It works as expected in this case.

@Jon is this by design? I personally don’t see the reason not to insert the credential with the same ID as the JSON file if it does not exists.

Hey @sitio-couto,

I believe this is by design, The ID is likely to be auto incrementing so if you were to jump in add say something at ID 50 but your database is currently on ID 10 when it does get to 50 it is going to hit an error which would be a bit of an issue.

@Jon, makes sense.

Thanks for the help!

1 Like