Skip to content

Error on drop TableForeignKey without name #9432

Closed

Description

@iJhefe

Issue Description

When drop a FK what name was generated by TypeORM (without a name in TableForeignKey) the query generated by dropForeignKey is setting the FK name as 'undefined'

Expected Behavior

Generate FK name like method createForeignKey

 ALTER TABLE "some_table" DROP CONSTRAINT "FK_436590330fb0eee0a7fa10dc49b"

Actual Behavior

Generate 'undefined' FK name

 ALTER TABLE "some_table" DROP CONSTRAINT "undefined"

Steps to Reproduce

  1. Create a migration what should create a table FK using TableForeignKey
  2. Run the migration
  3. Revert it
export class someMigration1664970153005 implements MigrationInterface {
 private readonly table = 'some_table';

  private readonly column = new TableColumn({
    name: 'column_name',
    type: 'int',
  });

  private readonly foreignKey = new TableForeignKey({
    columnNames: [this.column.name],
    referencedColumnNames: ['id'],
    referencedTableName: this.table,
  });

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.createForeignKey(this.table, this.foreignKey);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.dropForeignKey(this.table, this.foreignKey);
  }
}

My Environment

Dependency Version
Operating System Win 10
Node.js version 16.14.2
Typescript version 4.7.4
TypeORM version 0.3.9

Additional Context

I've tested only in a Postgres DB, others DB Type can has the same issue

Relevant Database Driver(s)

DB Type Reproducible
aurora-mysql no
aurora-postgres no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql no
nativescript no
oracle no
postgres yes
react-native no
sap no
spanner no
sqlite no
sqlite-abstract no
sqljs no
sqlserver no

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

  • ✅ Yes, I have the time, and I know how to start.
  • ✖️ Yes, I have the time, but I don't know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

Activity

  1. KiranPatil30 commented on Oct 8, 2022

    @KiranPatil30

    Hello Sir , Can You Assign This Issue to Me?

  2. added a commit that references this issue on Oct 12, 2022
    3592a52
  3. added a commit that references this issue on Nov 4, 2022
    efb4168
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions