Importing workflows with CLI don't keep ids?

I’m trying to export / import workflows through several environments (dev to prod°),

Actually, I’m clicking on the Download button in the UI to commit this file in my git repository.

Then, I deploy these files and use the CLI to import these files through a n8n import:workflow --separate --input my-directory-of-workflows.

After a first successful deployment, I have an error related to an index :

Importing workflows...
An error occurred while exporting workflows. See log messages for details.
duplicate key value violates unique constraint "IDX_a252c527c4c89237221fe2c0ab"

I understand there is unicity constraint on the name workflow column.

I try to remove this index to see if it could help me. (this is not a good idea, but that was for testing purpose)

The import works, but now, it seems that ids are not kept during import.

This is bad for me as I’m losing relations between workflows, like the error workflow, or when I start some workflows from other workflows.
This also make duplicates each time I try to deploy workflow updates. Instead of updating workflows.

I try to update json files by making the id a number instead of a string, but this doesn’t help.

As the json workflow have an id, I would expect the import override the previous workflow with the same id, am I wrong ? Even if there is the same name, I think this is “normal” as the workflow could keep, or update its name ?

If I read CLI commands for n8n | Docs, I understand there is a worfklow override, and that’s what I am expecting ? Is this correct ?

I find also a mistake (I think) in the table webhook_entity, the column workflowId is not related with a foreign key to the workflow_entity table, maybe this could be useful ?
This should protect deletion from the workflow_entity table if there is a webhook_entity linked.

Thanks for replies

Hi @mdartic

I am sorry you are having these issues.

It seems to me that you might have an inconsistent state from the start, as I use this procedure constantly to update my local instance with data from a repository, just like you are planning on doing.

Are all your workflows uniquely named across instances? Also, you should never create workflows on the destination instance, as it would cause them to be overridden by future imports, as the IDs are used as keys for importing. My recommendation is to wipe the destination instance’s database and import again. You should see the IDs are kept the same.

If this doesn’t happen, I would ask you to inform the database system you are using and what n8n version you are currently running.

In regard to the webhook_entity, n8n has some defensive mechanisms internally that avoid this from happening, so unless the database is changed directly this shouldn’t happen.