n8n-io/n8n · error · TypeORMError

Cannot find relation ${propertyPath}. Wrong relation specifi

Error message

Cannot find relation ${propertyPath}. Wrong relation specified for @RelationId decorator.

What it means

Thrown by RelationIdMetadata.build when the relation name or factory passed to @RelationId does not resolve to any relation via findRelationWithPropertyPath. Identical mechanism to the RelationCount check: it accepts a string or a propertiesMap factory, resolves it during build, and throws TypeORMError if nothing matches.

Source

Thrown at packages/@n8n/typeorm/src/metadata/RelationIdMetadata.ts:106

		}
	}

	// ---------------------------------------------------------------------
	// Public Builder Methods
	// ---------------------------------------------------------------------

	/**
	 * Builds some depend relation id properties.
	 * This builder method should be used only after entity metadata, its properties map and all relations are build.
	 */
	build() {
		const propertyPath =
			typeof this.relationNameOrFactory === 'function'
				? this.relationNameOrFactory(this.entityMetadata.propertiesMap)
				: this.relationNameOrFactory;
		const relation = this.entityMetadata.findRelationWithPropertyPath(propertyPath);
		if (!relation)
			throw new TypeORMError(
				`Cannot find relation ${propertyPath}. Wrong relation specified for @RelationId decorator.`,
			);

		this.relation = relation;
	}
}

View on GitHub (pinned to 5ac6606e81)

Solutions

  1. Confirm the path passed to @RelationId names an actual @OneToMany/@ManyToOne/@ManyToMany/@OneToOne relation on the entity.
  2. Sync the string/factory with the current relation property name after renames.
  3. Remove the @RelationId property if the underlying relation no longer exists.

Example fix

// before
@RelationId((post) => post.author)
authorId: number;
// but the relation property is actually named 'owner'

// after
@RelationId((post) => post.owner)
authorId: number;
Defensive patterns

Strategy: validation

Validate before calling

function validateRelationIds(dataSource: DataSource): string[] {
  const problems: string[] = [];
  for (const meta of dataSource.entityMetadatas) {
    const relationPaths = new Set(meta.relations.map((r) => r.propertyPath));
    for (const ri of meta.relationIds) {
      const target =
        typeof ri.relationNameOrFactory === 'function'
          ? ri.relationNameOrFactory(meta.propertiesMap)
          : ri.relationNameOrFactory;
      if (!relationPaths.has(target)) {
        problems.push(`${meta.targetName}.@RelationId -> missing relation '${target}'`);
      }
    }
  }
  return problems;
}

Try / catch

try {
  await dataSource.initialize();
} catch (err) {
  if (err.message.includes('Wrong relation specified for @RelationId')) {
    // surface the bad relation path
  }
  throw err;
}

Prevention

When it happens

Trigger: Using @RelationId(() => Entity, 'missingRel') or a factory returning a non-existent path on the owning entity.

Common situations: Relation renamed/deleted without updating @RelationId arguments; pointing @RelationId at a non-relation field; refactor moving a relation between entities.

Related errors


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