I attempted to implement migration in TypeORM as shown below:
TableExample.entity.ts
@Entity({ name: 'table_example' })
export class TableExampleEntity {
constructor(properties : TableExampleInterface) {
this.id = properties.id;
}
@PrimaryColumn({
name: 'id',
type: 'uuid',
generated: 'uuid',
default: 'uuid_generate_v4()',
})
id? : string;
}
TableExample.interface.ts
export interface TableExampleInterface{
id? : string;
}
and migration file
import {MigrationInterface, QueryRunner, Table} from 'typeorm';
export class createSongEntities1591077091789 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(new Table({
name: 'table_example',
columns: [
{
name: 'id',
type: 'uuid',
generationStrategy: 'uuid',
default: 'uuid_generate_v4()',
isPrimary: true,
},
],
}));
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('table_example');
}
}
Upon running the migration, the node server threw the following error Stack trace
Error during migration run:
TypeError: Cannot read property 'id' of undefined
at new TableExampleEntity (...\src\entities\TableExample.entity.ts:17:34)
at EntityMetadata.create (...\src\metadata\EntityMetadata.ts:524:19)
at EntityMetadataValidator.validate (...\src\metadata-builder\EntityMetadataValidator.ts:112:47)
at ...\src\metadata-builder\EntityMetadataValidator.ts:45:56
at Array.forEach (<anonymous>)
at EntityMetadataValidator.validateMany (...\src\metadata-builder\EntityMetadataValidator.ts:45:25)
...
What could be the issue here? Any assistance would be greatly appreciated!