Critical Issue: Unable to Recover Workflows From Old Database After Config File Corruption

Hello n8n community,
I’m facing a critical and very strange issue where I cannot access my old workflows after my instance’s config file was found to be corrupted. I would be extremely grateful for any expert insight.
The Situation:
My self-hosted n8n (Docker on Windows) stopped working. After a long troubleshooting session, we discovered the root cause: the .n8n/config file was corrupted and almost empty (only 56 bytes), meaning the encryption key was lost.
However, my database.sqlite file is safe and intact (~7MB), and I have a backup of it.
The Problem:
We attempted a standard recovery procedure:

  1. Started a fresh, latest-version n8n container.
  2. Completed the new owner setup. This successfully created a new, healthy config file with a new encryption key.
  3. Stopped the container.
  4. Swapped the new, empty database.sqlite with my old, data-rich database.sqlite backup file.
  5. Restarted the container.
    The Unexpected Result:
    After restarting, n8n still shows a completely empty instance (the “set up first credential” screen), and all my old workflows are gone. It seems n8n is ignoring or overwriting the restored database.sqlite file, likely because it cannot decrypt the credentials within it (due to the new key).
    What We Have Tried (to rule everything out):
  • We confirmed this is not a Docker volume path issue (we tested with absolute paths).
  • We confirmed this is not a file permission issue (we are running the container with -user root).
  • Crucially, we even tried running an older version of n8n (0.236.3) with the old database file. Even the older version did not recognize the data and showed the “Set up owner account” screen.
    My Core Question:
    Is this expected behavior? When n8n detects an encryption key mismatch, is it designed to discard/overwrite the entire database, including the unencrypted workflow data?
    Is there any known procedure to recover the (unencrypted) workflows from a database.sqlite file when the original encryption key is permanently lost?
    Thank you for your time and help. This has been a very difficult issue to diagnose.

This is a painful situation, and unfortunately you’ve run into one of the most fragile points of n8n’s architecture: the encryption key (N8N_ENCRYPTION_KEY) that’s stored in .n8n/config.

Let me break this down carefully:


1. Why the workflows aren’t appearing

  • n8n stores two kinds of data in the database (database.sqlite):

    • Workflows, executions, and metadata → these are not encrypted.

    • Credentials → these are encrypted using the key from the config file.

  • Normally, if you lose the encryption key, you should still see workflows and executions (but credentials would be broken/unusable).

  • In your case, since you’re seeing the “setup owner” screen, that suggests n8n thinks the DB is brand new. That happens if:

    • The DB schema doesn’t match the current n8n version and migration failed.

    • Or n8n actually created a new DB file instead of using your backup (path or mount issue).

    • Or your DB has the data but the “ownership” row (the user record in user table) is gone or unreadable.


2. What should happen if the encryption key is lost

  • Expected behavior:

    • Workflows are still visible.

    • Credentials are not usable (they show as empty or broken).

  • It is not expected that n8n wipes the whole DB just because the key doesn’t match.
    So if you’re not seeing any workflows, that points to something deeper (e.g., n8n ignoring or failing to read the DB file).


3. Recovery options

Since your database file is intact, you still have your workflows. Options:

A. Verify the DB really has your workflows

  1. Install SQLite CLI (sqlite3 database.sqlite).

  2. Run:

    .tables
    SELECT id, name FROM workflow_entity;
    
    
    • If you see rows here → your workflows are safe inside the DB.

    • If it’s empty → then the corruption went beyond just config.

B. Extract workflows manually

If workflows exist in the DB:

  1. Dump them:

    SELECT id, name, nodes, connections FROM workflow_entity;
    
    
  2. Copy these JSONs into files.

  3. Import them into a fresh n8n instance via the UI.

This way you bypass the missing encryption key (since workflows aren’t encrypted).

C. Credentials are gone unless…

Credentials are AES-encrypted with the lost key. If the key file is really corrupted/empty and you have no backup, credentials cannot be decrypted. You’ll need to re-enter them manually after importing workflows.


4. Why you’re seeing the “setup” screen

  • That’s tied to the user table (user and settings tables). If those entries are unreadable (e.g., schema mismatch after upgrading), n8n assumes this is a fresh instance.

  • This doesn’t mean workflows are gone — just that n8n isn’t loading them.


5. Practical recovery steps

  1. Check DB contents with SQLite manually.

  2. Dump workflows to JSON.

  3. Re-import into fresh instance.

  4. Recreate credentials manually.

  5. (Optional) If user table is intact, you can also manually set up the owner account by editing rows, but importing workflows is usually simpler.


:white_check_mark: Answering your core questions directly:

  • Is it expected that workflows are lost if the key is lost?
    No. Only credentials are encrypted. Workflows should still be present.

  • Can you recover workflows from the DB without the key?
    Yes. Use SQLite to dump workflows and re-import them.
    Credentials cannot be recovered without the key.

  • step by step so you can pull your workflows out of the SQLite database and re-import them into a fresh n8n instance.


1. Install SQLite CLI

If you don’t already have it:

  • On Linux (WSL, or Git Bash if on Windows):

    sudo apt-get update && sudo apt-get install sqlite3 -y
    
    
  • On Windows: download sqlite-tools, unzip, and put sqlite3.exe in your PATH or same folder as the DB.


2. Open your database

sqlite3 database.sqlite


3. Check tables

Inside SQLite:

.tables

You should see something like:

credentials_entity   execution_entity   workflow_entity   user   settings


4. Verify workflows exist

Run:

SELECT id, name FROM workflow_entity;

  • If you see rows → your workflows are safe.

  • If it’s empty → something else went wrong (we’ll need to check migrations).


5. Dump workflows to JSON

Now export all workflows:

.mode json
.output workflows.json
SELECT id, name, nodes, connections FROM workflow_entity;
.output stdout

This will create a workflows.json file in your current folder.
Each row will look like:

{"id":1,"name":"My Workflow","nodes":"[{...}]", "connections":"{...}"}


6. (Optional) Dump everything for backup

If you want all workflow columns:

.output full_workflows.json
SELECT * FROM workflow_entity;
.output stdout


7. Import into fresh n8n

  • Start a clean n8n instance (with a new config + new DB).

  • Open the UI → Import workflow → paste the JSON for each workflow.

:warning: Note: credentials won’t come back (they’re encrypted with your lost key). You’ll need to re-add them manually.


:white_check_mark: This way, you can fully recover your workflows from the DB, even without the lost encryption key. Hope you may recover your workflows.:folded_hands:


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.