{"record":{"id":"05a3f48cb2566d67","repo":"n8n-io/n8n","slug":"entity-entitymetadata-name-does-not-have-a-pr","errorCode":null,"errorMessage":"Entity \"${entityMetadata.name}\" does not have a primary column. Primary column is required to have in all your entities. Use @PrimaryColumn decorator to add a primary column to your entity.","messagePattern":"Entity \"(.+?)\" does not have a primary column\\. Primary column is required to have in all your entities\\. Use @PrimaryColumn decorator to add a primary column to your entity\\.","errorType":"exception","errorClass":"MissingPrimaryColumnError","httpStatus":null,"severity":"critical","filePath":"packages/@n8n/typeorm/src/metadata-builder/EntityMetadataValidator.ts","lineNumber":53,"sourceCode":"\n\t/**\n\t * Validates all given entity metadatas.\n\t */\n\tvalidateMany(entityMetadatas: EntityMetadata[], driver: Driver) {\n\t\tentityMetadatas.forEach((entityMetadata) =>\n\t\t\tthis.validate(entityMetadata, entityMetadatas, driver),\n\t\t);\n\t\tthis.validateDependencies(entityMetadatas);\n\t\tthis.validateEagerRelations(entityMetadatas);\n\t}\n\n\t/**\n\t * Validates given entity metadata.\n\t */\n\tvalidate(entityMetadata: EntityMetadata, allEntityMetadatas: EntityMetadata[], driver: Driver) {\n\t\t// check if table metadata has an id\n\t\tif (!entityMetadata.primaryColumns.length && !entityMetadata.isJunction)\n\t\t\tthrow new MissingPrimaryColumnError(entityMetadata);\n\n\t\t// if entity has multiple primary keys and uses custom constraint name,\n\t\t// then all primary keys should have the same constraint name\n\t\tif (entityMetadata.primaryColumns.length > 1) {\n\t\t\tconst areConstraintNamesEqual = entityMetadata.primaryColumns.every(\n\t\t\t\t(columnMetadata, i, columnMetadatas) =>\n\t\t\t\t\tcolumnMetadata.primaryKeyConstraintName === columnMetadatas[0].primaryKeyConstraintName,\n\t\t\t);\n\t\t\tif (!areConstraintNamesEqual) {\n\t\t\t\tthrow new TypeORMError(\n\t\t\t\t\t`Entity ${entityMetadata.name} has multiple primary columns with different constraint names. Constraint names should be the equal.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// validate if table is using inheritance it has a discriminator\n\t\t// also validate if discriminator values are not empty and not repeated\n\t\tif (","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/metadata-builder/EntityMetadataValidator.ts#L35-L71","documentation":"Thrown by EntityMetadataValidator.validate via MissingPrimaryColumnError when an entity has zero primary columns and is not a junction (isJunction) table. The guard is `if (!entityMetadata.primaryColumns.length && !entityMetadata.isJunction)`. Every persistable entity must declare a primary key.","triggerScenarios":"Defining an @Entity class with no @PrimaryColumn, @PrimaryGeneratedColumn, or @ObjectIdColumn; only view entities (which set isJunction/other flags) are exempt, but plain entities are not.","commonSituations":"New entity authored without a PK decorator; renaming @PrimaryGeneratedColumn to a plain @Column during refactor; migrating from MongoDB ObjectId columns and forgetting the decorator.","solutions":["Add @PrimaryGeneratedColumn() (auto-increment) or @PrimaryColumn() (user-supplied) to one property.","For composite keys, use multiple @PrimaryColumn decorators on each constituent field.","If the class is intentionally a pure view, mark it with @ViewEntity so it is excluded from the PK requirement path."],"exampleFix":"// before\n@Entity()\nexport class AuditLog {\n  @Column() action: string;\n}\n\n// after\n@Entity()\nexport class AuditLog {\n  @PrimaryGeneratedColumn() id: number;\n  @Column() action: string;\n}","handlingStrategy":"validation","validationCode":"function assertAllEntitiesHavePk(dataSource: DataSource): void {\n  const missing = dataSource.entityMetadatas\n    .filter((m) => !m.isJunction && m.primaryColumns.length === 0)\n    .map((m) => m.targetName);\n  if (missing.length) {\n    throw new Error('Entities without a primary column: ' + missing.join(', '));\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await dataSource.initialize();\n} catch (err) {\n  if (err.message.includes('does not have a primary column')) {\n    // surface the entity name; add @PrimaryGeneratedColumn\n  }\n  throw err;\n}","preventionTips":["Establish a project lint rule / template that every @Entity class must begin with a @PrimaryGeneratedColumn line.","Run the post-init PK validator above in CI.","Code-review new entities specifically for the presence of a primary-key decorator."],"tags":["primary-key","entity","metadata","startup"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}