{"record":{"id":"0a26a422daad5c57","repo":"n8n-io/n8n","slug":"sqlite-does-not-support-autoincrement-on-composite","errorCode":null,"errorMessage":"Sqlite does not support AUTOINCREMENT on composite primary key","messagePattern":"Sqlite does not support AUTOINCREMENT on composite primary key","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/typeorm/src/driver/sqlite-abstract/AbstractSqliteQueryRunner.ts","lineNumber":1486,"sourceCode":"\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * Builds create table sql.\n\t */\n\tprotected createTableSql(\n\t\ttable: Table,\n\t\tcreateForeignKeys?: boolean,\n\t\ttemporaryTable?: boolean,\n\t): Query {\n\t\tconst primaryColumns = table.columns.filter((column) => column.isPrimary);\n\t\tconst hasAutoIncrement = primaryColumns.find(\n\t\t\t(column) => column.isGenerated && column.generationStrategy === 'increment',\n\t\t);\n\t\tconst skipPrimary = primaryColumns.length > 1;\n\t\tif (skipPrimary && hasAutoIncrement)\n\t\t\tthrow new TypeORMError(`Sqlite does not support AUTOINCREMENT on composite primary key`);\n\n\t\tconst columnDefinitions = table.columns\n\t\t\t.map((column) => this.buildCreateColumnSql(column, skipPrimary))\n\t\t\t.join(', ');\n\t\tconst [database] = this.splitTablePath(table.name);\n\t\tlet sql = `CREATE TABLE ${this.escapePath(table.name)} (${columnDefinitions}`;\n\n\t\tlet [databaseNew, tableName] = this.splitTablePath(table.name);\n\t\tconst newTableName = temporaryTable\n\t\t\t? `${databaseNew ? `${databaseNew}.` : ''}${tableName.replace(/^temporary_/, '')}`\n\t\t\t: table.name;\n\n\t\t// need for `addColumn()` method, because it recreates table.\n\t\ttable.columns\n\t\t\t.filter((column) => column.isUnique)\n\t\t\t.forEach((column) => {\n\t\t\t\tconst isUniqueExist = table.uniques.some(\n\t\t\t\t\t(unique) => unique.columnNames.length === 1 && unique.columnNames[0] === column.name,","sourceCodeStart":1468,"sourceCodeEnd":1504,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/driver/sqlite-abstract/AbstractSqliteQueryRunner.ts#L1468-L1504","documentation":"SQLite only permits AUTOINCREMENT on a single INTEGER PRIMARY KEY column. createTableSql() detects a composite primary key (more than one primary column) where at least one column is generated with the 'increment' strategy, and throws TypeORMError before generating any DDL. This is a schema-design constraint enforced up front.","triggerScenarios":"Creating/recreating a table (CREATE TABLE path, including the table-copy used by ALTER workarounds) whose entity/metadata marks multiple columns as @PrimaryColumn and one of them as @PrimaryGeneratedColumn({ strategy: 'increment' }) / generationStrategy 'increment'.","commonSituations":"Porting a Postgres schema with a composite PK plus a serial column to SQLite; entities using a composite key that also mark an id column as auto-increment; test fixtures mirroring such a schema on SQLite.","solutions":["Split the auto-increment column out of the composite key — on SQLite it must be the sole primary column.","For composite keys, drop the auto-increment strategy and assign IDs manually (or use a sequence/trigger).","Redesign the entity so only one column is PRIMARY KEY if you need AUTOINCREMENT.","If multi-column uniqueness is what you need, keep a single auto-increment PK and add a separate composite unique index instead."],"exampleFix":"// before — composite PK with one auto-increment column\n@PrimaryGeneratedColumn({ strategy: 'increment' })\nid: number;\n@PrimaryColumn() tenantId: number;\n\n// after — single auto-increment PK, composite uniqueness via index\n@PrimaryGeneratedColumn({ strategy: 'increment' })\nid: number;\n@Column() tenantId: number;\n@Index('UQ_tenant_id', ['id', 'tenantId'], { unique: true })","handlingStrategy":"validation","validationCode":"function isValidSqlitePrimaryKey(columns: { isPrimary: boolean; isGenerated: boolean; generationStrategy?: string }[]): boolean {\n  const primaries = columns.filter((c) => c.isPrimary);\n  const autoInc = primaries.some(\n    (c) => c.isGenerated && c.generationStrategy === 'increment',\n  );\n  return !(primaries.length > 1 && autoInc);\n}\n\nif (!isValidSqlitePrimaryKey(entityColumns)) {\n  throw new Error('SQLite cannot combine AUTOINCREMENT with a composite primary key');\n}","typeGuard":"const hasCompositeAutoIncrementPk = (table: Table): boolean => {\n  const primaries = table.columns.filter((c) => c.isPrimary);\n  const autoInc = primaries.some(\n    (c) => c.isGenerated && c.generationStrategy === 'increment',\n  );\n  return primaries.length > 1 && autoInc;\n};","tryCatchPattern":null,"preventionTips":["On SQLite, keep AUTOINCREMENT on a single INTEGER PRIMARY KEY column.","Model composite uniqueness with a separate unique index, not a composite PK.","Validate entity metadata against driver capabilities before sync."],"tags":["database","sqlite","schema-design"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}