Skip to content

Error generating migration for a new table with composite foreign key as a primary key #5729

@golergka

Description

@golergka

Issue type:

[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[ ] latest
[ ] @next
[x] 0.2.22
[x] 0.2.24

Steps to reproduce or a small repository showing the problem:

  1. Create the following schema with previous migrations (no problems there):
export enum UserLoginMethod {
    DeviceId = "device_id",
    Facebook = "facebook",
    Bot = "bot"
}

@Entity()
// We have to create a composite index for it to be a target of a foregn key
@Index("user_login_method", ["id", "loginMethod"], { unique: true })
export class User {

    @PrimaryGeneratedColumn()
    id: number;

    @Column({
        type: "enum",
        enum: UserLoginMethod
    })
    loginMethod: UserLoginMethod;

}
  1. Create a new entity:
@Entity()
export class UserDeviceId {

    @OneToOne(type => User, { primary: true })
    @JoinColumn([
        { name: "userId", referencedColumnName: "id" },
        { name: "userLoginMethod", referencedColumnName: "loginMethod"}
    ])
    user: User;

    @Column({ unique: true })
    @Index()
    deviceId: string;
}
  1. Try to generate a new migration:
typeorm migration:generate -n UserDeviceId

Expected result:

A new migration is created, with a new table that uses a composite foreign key as a primary column.

Actual result:

Error during migration generation:
TypeError: Cannot read property 'map' of undefined
    at PostgresQueryRunner.createEnumTypeSql (/usr/lib/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:2398:38)
    at PostgresQueryRunner.<anonymous> (/usr/lib/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:420:69)        at step (/usr/lib/node_modules/typeorm/node_modules/tslib/tslib.js:136:27)
    at Object.next (/usr/lib/node_modules/typeorm/node_modules/tslib/tslib.js:117:57)
    at fulfilled (/usr/lib/node_modules/typeorm/node_modules/tslib/tslib.js:107:62)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions