n8n-io/n8n · error · InitializedRelationError
Array initializations are not allowed in entity relations…
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.
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.
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
- 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.
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
- Cannot find relation
- Cannot find relation
- Entity metadata for # was not found. Check if you specified…
- Auto shutdown timeout must be non-negative, got
- Azure Blob container name not configured. Please set…
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/c2f60884b4c62f0e.
Report an issue: GitHub.
Appendix: 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)