Search code examples
nestjsentityfield

Entity dynamic field does not work - error in compiling - what is the problem?


The entity does not work - what is the problem?

@Entity('banks')
export class Banks {
  [key: string]: BanksStructure;
  constructor(banks?: Partial<Banks>) {
    Object.assign(this, banks);
  }
}

I get this error:

ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)...
MissingPrimaryColumnError: Entity "Banks" does not have a primary column. Primary column is required to have in all your entities. Use @PrimaryColumn decorator to add a primary column to your entity.


Solution

  • As the error states your entity does not have a primary column. Please refer to the documentation for specifying it: https://typeorm.io/entities#primary-columns.