SQLite Migration error: SQLITE_CONSTRAINT: UNIQUE constraint failed: workflow_history.versionId

Describe the problem/error/question

I have a self-hosted solution and all is working on version 2.0.1.
I tried updating by following all stable versions up to 2.1.4, but from 2.0.2 I got this migration error.

I’m using n8n for personal projects, I didn’t do nothing fancy or custom changes in the source code.

What is the error message (if any)?

Initializing n8n process
n8n ready on ::, port 5678
Migrations in progress, please do NOT stop the process.
Starting migration BackfillMissingWorkflowHistoryRecords1765448186933
Migration "BackfillMissingWorkflowHistoryRecords1765448186933" failed, error: SQLITE_CONSTRAINT: UNIQUE constraint failed: workflow_history.versionId
There was an error running database migrations
SQLITE_CONSTRAINT: UNIQUE constraint failed: workflow_history.versionId

Information on your n8n setup

instance information

Debug info

core

  • n8nVersion: 2.0.1
  • platform: docker (self-hosted)
  • nodeJsVersion: 22.21.0
  • nodeEnv: production
  • database: sqlite
  • executionMode: regular
  • concurrency: -1
  • license: enterprise (production)
  • consumerId: 7d6b7cc4-831c-463e-a8f8-bf856450efcf

storage

  • success: all
  • error: all
  • progress: false
  • manual: true
  • binaryMode: filesystem

pruning

  • enabled: true
  • maxAge: 336 hours
  • maxCount: 10000 executions

client

  • userAgent: mozilla/5.0 (macintosh; intel mac os x 10_15_7) applewebkit/537.36 (khtml, like gecko) chrome/143.0.0.0 safari/537.36
  • isTouchDevice: false

Generated at: 2025-12-31T13:24:55.360Z

This looks to be erroring because there is a duplicate of something in your workflow history, so when it tries to migrate it fails. You might need to clear that database perhaps.

Yes, I understand that there is a duplicate, but I don’t really know why it happened and how. As I said, I was using n8n normally..
However, how can I clear that database? There is a guide somewhere?

if you can acsess your n8n instance, just delete the entire workflow history from the executions tab, i believe thats what the error means, as for the logs, its in the n8n instance files. Look in your n8n instance files for the workflow history. This is happening because n8n forces a unique constraint on workflow history and you have a duplicate which is why this is occuring.