n8n-io/n8n · error · InitializedRelationError

Array initializations are not allowed in entity relations. P

Error message

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.

What it means

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.

Source

Thrown at packages/@n8n/typeorm/src/metadata-builder/EntityMetadataValidator.ts:148

			);
			if (virtualColumn)
				throw new TypeORMError(
					`Column "${virtualColumn.propertyName}" of Entity "${entityMetadata.name}" is defined as VIRTUAL, but Postgres supports only STORED generated columns.`,
				);
		}

		// check if relations are all without initialized properties
		const entityInstance = entityMetadata.create(undefined, {
			fromDeserializer: true,
		});
		entityMetadata.relations.forEach((relation) => {
			if (relation.isManyToMany || relation.isOneToMany) {
				// we skip relations for which persistence is disabled since initialization in them cannot harm somehow
				if (relation.persistenceEnabled === false) return;

				// get entity relation value and check if its an array
				const relationInitializedValue = relation.getEntityValue(entityInstance);
				if (Array.isArray(relationInitializedValue)) throw new InitializedRelationError(relation);
			}
		});

		// validate relations
		entityMetadata.relations.forEach((relation) => {
			// check OnDeleteTypes
			if (
				driver.supportedOnDeleteTypes &&
				relation.onDelete &&
				!driver.supportedOnDeleteTypes.includes(relation.onDelete)
			) {
				throw new TypeORMError(
					`OnDeleteType "${relation.onDelete}" is not supported for ${driver.options.type}!`,
				);
			}

			// check OnUpdateTypes
			if (

View on GitHub (pinned to 5ac6606e81)

Solutions

  1. Remove the = [] initializer so the relation field is declared but not initialized.
  2. If a default is required for non-persisted code paths, initialize lazily in the constructor only for transient use, or use a getter.
  3. Run a lint rule / grep for '= []' on @OneToMany / @ManyToMany properties to catch regressions.

Example fix

// before
@OneToMany(() => Post, (p) => p.author)
posts: Post[] = [];

// after
@OneToMany(() => Post, (p) => p.author)
posts!: Post[];
Defensive patterns

Strategy: validation

Validate before calling

function assertNoToManyArrayInitializers(
  entityClasses: Function[],
): string[] {
  const problems: string[] = [];
  for (const cls of entityClasses) {
    const instance = Object.create(cls.prototype) as Record<string, unknown>;
    for (const key of Object.keys(instance)) {
      if (Array.isArray(instance[key])) {
        problems.push(`${cls.name}#${key} is initialized to an array; to-many relations must not be initialized`);
      }
    }
  }
  return problems;
}

Try / catch

try {
  await dataSource.initialize();
} catch (err) {
  if (err.message.includes('Array initializations are not allowed in entity relations')) {
    // remove the '= []' initializer from the named property
  }
  throw err;
}

Prevention

When it happens

Trigger: Writing `@OneToMany(...) posts: Post[] = [];` (or a Set/array literal) on a to-many relation. Relations with persistenceEnabled === false are exempt; everything else is rejected.

Common situations: IDE auto-initializers; Angular/Vue style of defaulting arrays; copy-paste from a non-TypeORM codebase; refactor that adds = [] for template convenience.

Related errors


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/c2f60884b4c62f0e. Report an issue: GitHub.