小编Dat*_*ran的帖子

TypeORM:无法读取未定义的属性“id”

我尝试在 TypeORM 中使用迁移,如下所示:

表示例.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;

}
Run Code Online (Sandbox Code Playgroud)

表示例.interface.ts

export interface TableExampleInterface{
    id? : string;
}
Run Code Online (Sandbox Code Playgroud)

迁移文件

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, …
Run Code Online (Sandbox Code Playgroud)

migration typescript typeorm

2
推荐指数
1
解决办法
5416
查看次数

标签 统计

migration ×1

typeorm ×1

typescript ×1