Docker image n8nio/n8n:stable migration failure

Describe the problem/error/question

Migration failure on latest n8n:stable build. Image is currently looping: migration-failure-migration-failure…

Failures started last night about 10:30pm MT

What is the error message (if any)?

Connecting to stream…
2025-12-06T15:03:47.08806 Connecting to the container ‘n8n2’…
2025-12-06T15:03:47.16459 Successfully Connected to container: ‘n8n2’ [Revision: ‘n8n2–0000012’, Replica: ‘n8n2–0000012-5df9d8484b-dctmv’]
2025-12-06T15:03:16.3489881Z stdout F Permissions 0644 for n8n settings file /home/node/.n8n/config are too wide. This is ignored for now, but in the future n8n will attempt to change the permissions automatically. To automatically enforce correct permissions now set N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true (recommended), or turn this check off set N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=false.
2025-12-06T15:03:16.4028241Z stdout F Initializing n8n process
2025-12-06T15:03:18.1211669Z stdout F n8n ready on ::, port 5678
2025-12-06T15:03:18.4257942Z stdout F Migrations in progress, please do NOT stop the process.
2025-12-06T15:03:18.4260518Z stdout F Starting migration AddActiveVersionIdColumn1763047800000
2025-12-06T15:03:19.2584520Z stdout F Migration “AddActiveVersionIdColumn1763047800000” failed, error: insert or update on table “workflow_entity” violates foreign key constraint “FK_08d6c67b7f722b0039d9d5ed620”
2025-12-06T15:03:19.3309933Z stdout F There was an error running database migrations
2025-12-06T15:03:19.3313208Z stdout F insert or update on table “workflow_entity” violates foreign key constraint “FK_08d6c67b7f722b0039d9d5ed620”

Information on your n8n setup

  • n8n version: n8nio/n8n:stable
  • Database: PosGreSql
  • Running n8n via: n8nio/n8n:stable Docker in Azure Container App

Hello @Joseph_Forsmann, Welcome!

seems an issue with “activeVersionId” in “workflow_entity” table,

what’s your current n8n version? is it too old?

Hi Mohamed - thanks for replying. I’m trying to figure out how to see the ‘current n8n version’. I can run queries on n8n DB in PostGreSql. My container (in Azure Container App) is set to n8nio/n8n:stable

I suspect ‘stable’ got a new build sometime late yesterday, and migration to this new build is failing. To get back online quickly, I would like to hard-code the previous build instead of using stable. Do you know what the previous stable build was? Or please let me know the best way to check the current N8N version without using the web portal - which is not working due to this migration error.

So you’re always using the same tag and updating regularly?

You can try using n8n:latest (it’s basically the same as stable),

If you want a previous version, you could try 1.122.4 (or whichever version was working before the failure)..

the latest now is 1.122.5

1 Like

I’m back online.

I rolled back to version 1.122.4 and saw the same migration errors discussed above. I then rolled back further to build 1.121.3, and everything works.

To summarize the issue and fix… In Azure Container App, my Container ‘Image and tag’ setting was set to “n8nio/n8n:stable”. Last night, at 10:30pm MT, ‘stable’ (without me knowing) switches from a 1.121.* build to a 1.122.* build. This kicked off a database migration which was failing with:

Migration “AddActiveVersionIdColumn1763047800000” failed, error: insert or update on table “workflow_entity” violates foreign key constraint

This failing migration prevented my container from coming online - so no workflow executions.

Fix
Using az command line to hard-code previous n8n build number and create a new ‘Revision’ of the container.

az containerapp update -n [CONTAINER_APP_NAME] -g [RESOURCE_GROUP_NAME] --image docker.io/n8nio/n8n:1.121.3

After hard-coding build 1.121.3, you’ll no longer get unexpected upgrades and migrations.

A few other unrelated roadbumps:

  1. Make sure you are properly authenticated with az client: “az logout” followed by “az login”
  2. Make sure you are in the correct tenent: az account set --subscription [subscription-id-or-name]

NOTE: This is a ‘Get me back online quickly’ fix. This does not fix the migration issue between 1.121.* to 1.122.*

1 Like

I have the same problem. Does anyone know a solution to fix this issue and successfully update the n8n version?

1 Like

I’m having the same issue. The same foreign key constraint fails when updating from 1.121.3 to 1.122.x

It’s this migration that fails, with the same message as above:

Migration "AddActiveVersionIdColumn1763047800000" failed, error: insert or update on table "workflow_entity" violates foreign key constraint "FK_08d6c67b7f722b0039d9d5ed620"
DETAIL: Key (activeVersionId)=(925b481f-c4b0-4bf9-b73e-ee1f82a2de59) is not present in table "workflow_history".
STATEMENT: UPDATE "workflow_entity"
    SET "activeVersionId" = "versionId"
    WHERE "active" = true

I went into the database and struggle to find any foreign key constraint by this name.

This should give a list of all constraints in the database, but doesn’t list the one above.

SELECT con.*
    FROM pg_catalog.pg_constraint con
        INNER JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid
        INNER JOIN pg_catalog.pg_namespace nsp ON nsp.oid = connamespace;

This is what the schema of my `workflow_entity` table looks like:

                                                           Table "public.workflow_entity"
     Column     |            Type             | Collation | Nullable |         Default         | Storage  | Compression | Stats target | Description
----------------+-----------------------------+-----------+----------+-------------------------+----------+-------------+--------------+-------------
 name           | character varying(128)      |           | not null |                         | extended |             |              |
 active         | boolean                     |           | not null |                         | plain    |             |              |
 nodes          | json                        |           | not null |                         | extended |             |              |
 connections    | json                        |           | not null |                         | extended |             |              |
 createdAt      | timestamp(3) with time zone |           | not null | CURRENT_TIMESTAMP(3)    | plain    |             |              |
 updatedAt      | timestamp(3) with time zone |           | not null | CURRENT_TIMESTAMP(3)    | plain    |             |              |
 settings       | json                        |           |          |                         | extended |             |              |
 staticData     | json                        |           |          |                         | extended |             |              |
 pinData        | json                        |           |          |                         | extended |             |              |
 versionId      | character(36)               |           | not null |                         | extended |             |              |
 triggerCount   | integer                     |           | not null | 0                       | plain    |             |              |
 id             | character varying(36)       |           | not null |                         | extended |             |              |
 meta           | json                        |           |          |                         | extended |             |              |
 parentFolderId | character varying(36)       |           |          | NULL::character varying | extended |             |              |
 isArchived     | boolean                     |           | not null | false                   | plain    |             |              |
 versionCounter | integer                     |           | not null | 1                       | plain    |             |              |
 description    | text                        |           |          |                         | extended |             |              |
Indexes:
    "workflow_entity_pkey" PRIMARY KEY, btree (id)
    "IDX_workflow_entity_name" btree (name)
    "pk_workflow_entity_id" UNIQUE, btree (id)
Foreign-key constraints:
    "fk_workflow_parent_folder" FOREIGN KEY ("parentFolderId") REFERENCES folder(id) ON DELETE CASCADE
Referenced by:
    TABLE "processed_data" CONSTRAINT "FK_06a69a7032c97a763c2c7599464" FOREIGN KEY ("workflowId") REFERENCES workflow_entity(id) ON DELETE CASCADE
    TABLE "insights_metadata" CONSTRAINT "FK_1d8ab99d5861c9388d2dc1cf733" FOREIGN KEY ("workflowId") REFERENCES workflow_entity(id) ON DELETE SET NULL
    TABLE "workflow_history" CONSTRAINT "FK_1e31657f5fe46816c34be7c1b4b" FOREIGN KEY ("workflowId") REFERENCES workflow_entity(id) ON DELETE CASCADE
    TABLE "chat_hub_sessions" CONSTRAINT "FK_9f9293d9f552496c40e0d1a8f80" FOREIGN KEY ("workflowId") REFERENCES workflow_entity(id) ON DELETE SET NULL
    TABLE "workflow_dependency" CONSTRAINT "FK_a4ff2d9b9628ea988fa9e7d0bf8" FOREIGN KEY ("workflowId") REFERENCES workflow_entity(id) ON DELETE CASCADE
    TABLE "chat_hub_messages" CONSTRAINT "FK_acf8926098f063cdbbad8497fd1" FOREIGN KEY ("workflowId") REFERENCES workflow_entity(id) ON DELETE SET NULL
    TABLE "test_run" CONSTRAINT "FK_d6870d3b6e4c185d33926f423c8" FOREIGN KEY ("workflowId") REFERENCES workflow_entity(id) ON DELETE CASCADE
    TABLE "shared_workflow" CONSTRAINT "FK_daa206a04983d47d0a9c34649ce" FOREIGN KEY ("workflowId") REFERENCES workflow_entity(id) ON DELETE CASCADE
    TABLE "execution_entity" CONSTRAINT "fk_execution_entity_workflow_id" FOREIGN KEY ("workflowId") REFERENCES workflow_entity(id) ON DELETE CASCADE
    TABLE "webhook_entity" CONSTRAINT "fk_webhook_entity_workflow_id" FOREIGN KEY ("workflowId") REFERENCES workflow_entity(id) ON DELETE CASCADE
    TABLE "workflow_statistics" CONSTRAINT "fk_workflow_statistics_workflow_id" FOREIGN KEY ("workflowId") REFERENCES workflow_entity(id) ON DELETE CASCADE
    TABLE "workflows_tags" CONSTRAINT "fk_workflows_tags_workflow_id" FOREIGN KEY ("workflowId") REFERENCES workflow_entity(id) ON DELETE CASCADE
Triggers:
    workflow_version_increment BEFORE UPDATE ON workflow_entity FOR EACH ROW EXECUTE FUNCTION increment_workflow_version()

This only references the foreign key constraint to `fk_workflow_parent_folder`.

For reference, I run the Community edition + Registered license. So I do have access to and use folders.

Since the error message also mentions the workflow_history table, I wonder if it’s a combination with a data issue. Some orphaned data from 2years of running maybe.

Further help is appreciated.

EDIT 10:20UTC

I followed up on the failed constraint to the `workflow_history` table. The error message basically says, that it tries to update a workflow_entity, but this entity has no corresponding versions in the `workflow_entity`. From what it looks like, because the community edition deletes workflow versions after a day, you end up having workflows with no history records in the `workflow_history” table, thus failing this constraint. If you go to a previous version, make an edit, save, update to 1.122.5, then it runs the migration successfully. However with 50+ workflows, that is a very impractical workaround and the migration should be patched to account for this. // @mohamed3nan

6 Likes

same problem here; just updated from 1.120.4 to stable and had to rollback

I would use the n8n API (via the n8n node) to bulk-update all workflows with dummy changes for now, to generate workflow history as you mentioned, if I don’t want to wait for this to be identified as a bug, fixed, etc..

4 Likes

We ran into the same problem. Our prod instance is locked down, so we can’t just update the workflows. Rolled back for now.

I have this issue too after updating to a 1.122.x release. I am also on the community version. - rollbacking back to 1.121.x for now, but I would love to see a fix.

Good news, It seems it got fixed in latest version

3 Likes

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