Unable to import version 1.x data via entities after upgrading n8n to 2.x

Description:
I am currently upgrading my n8n instance from version 1.123.5 to 2.4.6 . My original setup used a custom Docker image (based on the official image but bundled with Python and various cloud provider SDKs for executing commands). As part of this upgrade, I am also migrating the database to PostgreSQL .

While the deployment using Docker Compose was successful, I am encountering several critical errors when trying to import my old data using the entities command.

The problems are as follows:

  1. Encryption Error:
    Even though I have strictly confirmed that the N8N_ENCRYPTION_KEY is identical between the old and new instances, I get the following error:
    error:1C80006B:Provider routines::wrong final block length
    This suggests a decryption failure, but the key remains unchanged.

  2. Migration State Mismatch:
    When running the import, I receive the following migration-related error:
    Migration timestamp mismatch. Import data: CreateWorkflowPublishHistoryTable1764167920585 (1764167920585) does not match target database ExpandInsightsWorkflowIdLength1766500000000 (1766500000000).Cannot import data from different migration states.
    It seems the import:entities command is highly sensitive to the database schema version, making it difficult to migrate across major versions (v1.x to v2.x).

Observations:
Interestingly, when I use the standard n8n import:workflow and n8n import:credentials commands, everything works perfectly without any errors. The issue seems specific to the entities import.

I am looking for guidance from the community on how to properly use import:entities when moving between different versions and database types, or if there is a recommended alternative migration path for version 2.x.

Below is my docker-compose.yml file for reference:

version: '3.8'

services:
  # 1. Main n8n Instance (Broker & UI)
  n8n:
    image: n8nio/n8n:latest 
    container_name: n8n-main
    restart: always
    ports:
      - "127.0.0.1:5678:5678"
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
      - DB_POSTGRESDB_USER=${POSTGRES_USER}
      - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
      - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
      - N8N_HOST=${N8N_HOST}
      - N8N_PORT=${N8N_PORT}
      - N8N_PROTOCOL=${N8N_PROTOCOL}
      - WEBHOOK_URL=${WEBHOOK_URL}
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
      - TZ=${TZ}
      - NODES_EXCLUDE="[]"
      # Runner Mode Configuration
      - N8N_RUNNERS_ENABLED=true
      - N8N_RUNNERS_MODE=external
      - N8N_RUNNERS_AUTH_TOKEN=${N8N_RUNNERS_AUTH_TOKEN}
      - N8N_RUNNERS_BROKER_LISTEN_ADDRESS=0.0.0.0
      
      # Permissions and Code Node Config
      - N8N_CODE_ENABLE_PROCESS_ENV=${N8N_CODE_ENABLE_PROCESS_ENV}
      - NODE_FUNCTION_ALLOW_BUILTIN=${NODE_FUNCTION_ALLOW_BUILTIN}
    volumes:
      - ${DATA_PATH:-./n8n_data}:/home/node/.n8n
      - ${SHARED_FILES_PATH:-./shared-files}:/home/node/shared-files
    depends_on:
      postgres:
        condition: service_healthy
    networks:
      - n8n-network

  # 2. Task Runner
  n8n-runner:
    image: n8nio/runners:latest 
    container_name: n8n-runner
    restart: always
    environment:
      - N8N_RUNNERS_AUTH_TOKEN=${N8N_RUNNERS_AUTH_TOKEN}
      - N8N_RUNNERS_TASK_BROKER_URI=http://n8n-main:5679
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
      - TZ=${TZ}
      
      # Code Node Permissions for child_process and env access
      - N8N_CODE_ENABLE_PROCESS_ENV=${N8N_CODE_ENABLE_PROCESS_ENV}
      - NODE_FUNCTION_ALLOW_BUILTIN=${NODE_FUNCTION_ALLOW_BUILTIN}
      - NODE_FUNCTION_ALLOW_EXTERNAL=${NODE_FUNCTION_ALLOW_EXTERNAL} 
    volumes:
      - ${RUNNER_DATA_PATH:-./n8n_runner_data}:/home/node/.n8n
      - ${SHARED_FILES_PATH:-./shared-files}:/home/node/shared-files
    depends_on:
      - n8n
    networks:
      - n8n-network

  # 3. Database
  postgres:
    image: postgres:18
    container_name: n8n-postgres
    restart: always
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DB}
      - TZ=${TZ}
      - PGDATA=/var/lib/postgresql/data
    volumes:
      - ${DB_DATA_PATH:-./postgres_data}:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - n8n-network

networks:
  n8n-network:
    driver: bridge

My Environment Config:

# --- Database Configuration ---
POSTGRES_USER=n8n_user
POSTGRES_PASSWORD=<YOUR_POSTGRES_PASSWORD>
POSTGRES_DB=n8n_db

# --- n8n Core Configuration ---
# Webhook URL (used for external callbacks)
WEBHOOK_URL=https://<YOUR_DOMAIN>/
# Protocol and Host information
N8N_PROTOCOL=https
N8N_HOST=<YOUR_DOMAIN>
N8N_PORT=5678

# --- Security & Authentication ---
# IMPORTANT: This key must match the one from your previous instance to decrypt data
N8N_ENCRYPTION_KEY=<YOUR_ENCRYPTION_KEY>
N8N_RUNNERS_AUTH_TOKEN=<YOUR_RUNNER_AUTH_TOKEN>

# --- Localization ---
GENERIC_TIMEZONE=Asia/Shanghai
TZ=Asia/Shanghai

# --- Code Node / Execution Permissions ---
# Enable access to process.env within Code nodes
N8N_CODE_ENABLE_PROCESS_ENV=true
# Allow Code nodes to import all built-in modules (e.g., child_process, fs)
NODE_FUNCTION_ALLOW_BUILTIN=*
# Allow Code nodes to import external npm modules
NODE_FUNCTION_ALLOW_EXTERNAL=*

Information on your n8n setup

  • **n8n version:1.123.5
  • **Database (default: SQLite):SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):Docker
  • **Operating system:Alibaba cloud linux 3

Hi @gmmop !

This is expected behavior.
import:entities cannot be used across different major versions or different database types.

In n8n 2.x, the import:entities command requires the source data and the target database to be in the exact same migration state.
Because you are migrating from v1.x (SQLite) to v2.x (PostgreSQL), the schema and migration timestamps do not match, so the import is correctly blocked.

This is explicitly enforced by n8n to prevent data corruption.


Why this happens

  • import:entities is a low-level database import
  • It is strictly bound to the internal migration version
  • Major upgrades (1.x → 2.x) introduce breaking schema changes
  • Database type changes (SQLite → Postgres) are not supported for entity imports

That is why you see:

  • Migration timestamp mismatch
  • Encryption/decryption errors (side effect of incompatible entity structure)

Correct and supported migration path

According to the documentation, the only supported way to migrate across major versions and database types is:

  1. Upgrade the old instance to the latest 1.x
  2. Export data using:
  • n8n export:workflow
  • n8n export:credentials
  1. Set up the new 2.x + PostgreSQL instance
  2. Import using:
  • n8n import:workflow
  • n8n import:credentials

Your observation that these commands work correctly confirms this is the intended approach.


Key takeaway

  • import:entities is not a general migration tool
  • It only works when versions and migrations match exactly
  • It is not supported for:
    • 1.x → 2.x upgrades
    • SQLite → PostgreSQL migrations
  • Your setup is correct; the limitation is intentional
1 Like

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