Skip to content

[BUG]: if set closure-table primary key unsigned, it occurs FK error #9600

@shkangr

Description

@shkangr

Issue description

I want to use closure-table and if I set primary key ( unsigned ) , error comes out when migrate shcema

Expected Behavior

@Entity()
@Tree('closure-table', {
  closureTableName: 'category',
  ancestorColumnName: (column) => 'ancestor_' + column.propertyName,
  descendantColumnName: (column) => 'descendant_' + column.propertyName,
})
export class CategoryEntity {
  @PrimaryGeneratedColumn('increment', { type: 'bigint', unsigned: true })
  id: string
}

I defined CategoryEntity like this.
And I expected closure-table is created successfully when create table by typeorm migration

Actual Behavior

when migrate schema, error occures below

error: Error: Referencing column 'ancestor_id' and referenced column 'id' in foreign key constraint 'FK_ab837edaafe1cd64a7efb216db1' are incompatible.
migration-file         |     at Packet.asError (/usr/src/app/node_modules/mysql2/lib/packets/packet.js:728:17)
migration-file         |     at Query.execute (/usr/src/app/node_modules/mysql2/lib/commands/command.js:29:26)
migration-file         |     at PoolConnection.handlePacket (/usr/src/app/node_modules/mysql2/lib/connection.js:456:32)
migration-file         |     at PacketParser.onPacket (/usr/src/app/node_modules/mysql2/lib/connection.js:85:12)
migration-file         |     at PacketParser.executeStart (/usr/src/app/node_modules/mysql2/lib/packet_parser.js:75:16)
migration-file         |     at Socket.<anonymous> (/usr/src/app/node_modules/mysql2/lib/connection.js:92:25)
migration-file         |     at Socket.emit (events.js:400:28)
migration-file         |     at Socket.emit (domain.js:475:12)
migration-file         |     at addChunk (internal/streams/readable.js:293:12)
migration-file         |     at readableAddChunk (internal/streams/readable.js:267:9) {
migration-file         |   code: undefined,
migration-file         |   errno: 3780,
migration-file         |   sqlState: 'HY000',
migration-file         |   sqlMessage: "Referencing column 'ancestor_id' and referenced column 'id' in foreign key constraint 'FK_ab837edaafe1cd64a7efb216db1' are incompatible.",
migration-file         |   sql: 'ALTER TABLE `category_closure` ADD CONSTRAINT `FK_ab837edaafe1cd64a7efb216db1` FOREIGN KEY (`ancestor_id`) REFERENCES `category`(`id`) ON DELETE CASCADE ON UPDATE NO ACTION'

Steps to reproduce

set primary column option unsigned
@PrimaryGeneratedColumn('increment', { type: 'bigint', unsigned: true })

and do migraion. can reproduce

My Environment

Dependency Version
Node.js version 16.4.0
TypeORM version 0.3.11

Additional Context

how can I resolve this issue?

can't set any options at closure-table except tableName, ancestorColumnName, descendantColumnName

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, and I know how to start.

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