{"record":{"id":"c2f60884b4c62f0e","repo":"n8n-io/n8n","slug":"array-initializations-are-not-allowed-in-entity-re","errorCode":null,"errorMessage":"Array initializations are not allowed in entity relations. Please remove array initialization (= []) from \"${relation.entityMetadata.targetName}#${relation.propertyPath}\". This is ORM requirement to make relations to work properly. Refer docs for more information.","messagePattern":"Array initializations are not allowed in entity relations\\. Please remove array initialization \\(= \\[\\]\\) from \"(.+?)#(.+?)\"\\. This is ORM requirement to make relations to work properly\\. Refer docs for more information\\.","errorType":"exception","errorClass":"InitializedRelationError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/typeorm/src/metadata-builder/EntityMetadataValidator.ts","lineNumber":148,"sourceCode":"\t\t\t);\n\t\t\tif (virtualColumn)\n\t\t\t\tthrow new TypeORMError(\n\t\t\t\t\t`Column \"${virtualColumn.propertyName}\" of Entity \"${entityMetadata.name}\" is defined as VIRTUAL, but Postgres supports only STORED generated columns.`,\n\t\t\t\t);\n\t\t}\n\n\t\t// check if relations are all without initialized properties\n\t\tconst entityInstance = entityMetadata.create(undefined, {\n\t\t\tfromDeserializer: true,\n\t\t});\n\t\tentityMetadata.relations.forEach((relation) => {\n\t\t\tif (relation.isManyToMany || relation.isOneToMany) {\n\t\t\t\t// we skip relations for which persistence is disabled since initialization in them cannot harm somehow\n\t\t\t\tif (relation.persistenceEnabled === false) return;\n\n\t\t\t\t// get entity relation value and check if its an array\n\t\t\t\tconst relationInitializedValue = relation.getEntityValue(entityInstance);\n\t\t\t\tif (Array.isArray(relationInitializedValue)) throw new InitializedRelationError(relation);\n\t\t\t}\n\t\t});\n\n\t\t// validate relations\n\t\tentityMetadata.relations.forEach((relation) => {\n\t\t\t// check OnDeleteTypes\n\t\t\tif (\n\t\t\t\tdriver.supportedOnDeleteTypes &&\n\t\t\t\trelation.onDelete &&\n\t\t\t\t!driver.supportedOnDeleteTypes.includes(relation.onDelete)\n\t\t\t) {\n\t\t\t\tthrow new TypeORMError(\n\t\t\t\t\t`OnDeleteType \"${relation.onDelete}\" is not supported for ${driver.options.type}!`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// check OnUpdateTypes\n\t\t\tif (","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/metadata-builder/EntityMetadataValidator.ts#L130-L166","documentation":"Thrown by EntityMetadataValidator.validate via InitializedRelationError when an @OneToMany or @ManyToMany relation has its class field initialized to an array (e.g. posts: Post[] = []). The validator instantiates the entity, reads the relation's value, and if Array.isArray(...) it throws, naming the entity and propertyPath. Array initializers break relation persistence semantics in TypeORM.","triggerScenarios":"Writing `@OneToMany(...) posts: Post[] = [];` (or a Set/array literal) on a to-many relation. Relations with persistenceEnabled === false are exempt; everything else is rejected.","commonSituations":"IDE auto-initializers; Angular/Vue style of defaulting arrays; copy-paste from a non-TypeORM codebase; refactor that adds = [] for template convenience.","solutions":["Remove the = [] initializer so the relation field is declared but not initialized.","If a default is required for non-persisted code paths, initialize lazily in the constructor only for transient use, or use a getter.","Run a lint rule / grep for '= []' on @OneToMany / @ManyToMany properties to catch regressions."],"exampleFix":"// before\n@OneToMany(() => Post, (p) => p.author)\nposts: Post[] = [];\n\n// after\n@OneToMany(() => Post, (p) => p.author)\nposts!: Post[];","handlingStrategy":"validation","validationCode":"function assertNoToManyArrayInitializers(\n  entityClasses: Function[],\n): string[] {\n  const problems: string[] = [];\n  for (const cls of entityClasses) {\n    const instance = Object.create(cls.prototype) as Record<string, unknown>;\n    for (const key of Object.keys(instance)) {\n      if (Array.isArray(instance[key])) {\n        problems.push(`${cls.name}#${key} is initialized to an array; to-many relations must not be initialized`);\n      }\n    }\n  }\n  return problems;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await dataSource.initialize();\n} catch (err) {\n  if (err.message.includes('Array initializations are not allowed in entity relations')) {\n    // remove the '= []' initializer from the named property\n  }\n  throw err;\n}","preventionTips":["Lint for '= []' initializers on @OneToMany / @ManyToMany relation properties (custom ESLint rule or grep).","Disable IDE auto-initializers for entity relation fields.","Code-review to-many relations specifically for missing definite-assignment (!) in place of array literals."],"tags":["relation-initializer","array","relation","startup"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}