As I work on developing a web application (angular, nestjs, typeorm), I am faced with the challenge of linking two legacy user tables together within our existing system. Despite my efforts, I continue to encounter an error message related to column references. Specifically, I keep receiving the error "TypeORMError: Referenced column userid was not found in entity Foruser."
The table in question is the authentication table, which previously stored sensitive information such as user passwords.
@Index("pk_foruser", ["id"], { unique: true })
@Entity("foruser", { schema: "dbo" })
export class Foruser {
@PrimaryColumn("varchar", { name: "id", length: 28 })
id: string;
@OneToOne(() => Adbuinfo)
Profile: Relation<Adbuinfo>;
}
On the other hand, we have the User profile table containing permissions and application details.
@Index("pk_adbuinfo", ["userid"], { unique: true })
@Entity("adbuinfo", { schema: "dbo" })
export class Adbuinfo {
@PrimaryColumn("varchar", { name: "userid", length: 32 })
userid: string;
@OneToOne(() => Foruser, (Foruser) => Foruser.Profile, { cascade: true})
@JoinColumn({name: 'id', referencedColumnName: 'id'})
User: Relation<Foruser>;
}
Unfortunately, altering the primary key column names is not a feasible solution due to the usage of these tables in other applications.
Edit: Here is the complete stack trace of the error.
TypeORMError: Referenced column userid was not found in entity Foruser
at C:\Development\Web Adtakr-1\adtakr-service\src\metadata-builder\RelationJoinColumnBuilder.ts:151:27
at Array.map (<anonymous>)
at RelationJoinColumnBuilder.collectReferencedColumns (C:\Development\Web Adtakr-1\adtakr-service\src\metadata-builder\RelationJoinColumnBuilder.ts:143:32)
at RelationJoinColumnBuilder.build (C:\Development\Web Adtakr-1\adtakr-service\src\metadata-builder\RelationJoinColumnBuilder.ts:62:40)
at C:\Development\Web Adtakr-1\adtakr-service\src\metadata-builder\EntityMetadataBuilder.ts:180:60
at Array.forEach (<anonymous>)
at C:\Development\Web Adtakr-1\adtakr-service\src\metadata-builder\EntityMetadataBuilder.ts:173:22
at Array.forEach (<anonymous>)
at EntityMetadataBuilder.build (C:\Development\Web Adtakr-1\adtakr-service\src\metadata-builder\EntityMetadataBuilder.ts:166:14)
at ConnectionMetadataBuilder.buildEntityMetadatas (C:\Development\Web Adtakr-1\adtakr-service\src\connection\ConnectionMetadataBuilder.ts:106:11)
Any attempts to modify the names or references to the 'userid' column result in the error message shifting to the inability to locate 'userid' within Foruser.