Skip to content

fix: resolve nameless TableForeignKey on drop foreign key - #10744

Merged
gioboa merged 1 commit into
typeorm:masterfrom
taichunmin:dropForeignKey
Jan 5, 2026
Merged

gioboa merged 1 commit into
typeorm:masterfrom
taichunmin:dropForeignKey

Conversation

@taichunmin

Copy link
Copy Markdown
Contributor

Description of change

Fixes #9432 #9460

If a TableForeignKey is without a name on dropForeignKey so it's create a name like on createForeignKey.

#9460 only fix postgres. This PR fix all query runner.

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run format to apply prettier formatting
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #0000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change
  • The new commits follow conventions explained in CONTRIBUTING.md

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @taichunmin
is this PR still valid?

@taichunmin
taichunmin force-pushed the dropForeignKey branch 2 times, most recently from b263326 to 5d7feb8 Compare January 22, 2025 02:58
@taichunmin

Copy link
Copy Markdown
Contributor Author

I think this PR is still valid.

I already rebase to master and reformat the code.

@gioboa

gioboa commented Jan 22, 2025

Copy link
Copy Markdown
Collaborator

I already rebase to master and reformat the code.

Thanks 👍
I looked at the issues mentioned in the description, both are closed. am I missing something?

@taichunmin

Copy link
Copy Markdown
Contributor Author

Because original PR only fix postgres. This PR fix aurora, cockroach, mysql, oracle, sap, spanner, sql server.

@gioboa

gioboa commented Jan 22, 2025

Copy link
Copy Markdown
Collaborator

Nice 👏 I see, thanks, let's modify the description to make it more visible

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is ready to be merged.
@taichunmin Can I ask you to solve the conflicts please?

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Code Suggestions ✨

CategorySuggestion                                                                                                                                    Impact
Possible issue
Inconsistent foreign key name generation

Align the foreignKeyName method call in AuroraMysqlQueryRunner.ts with other
drivers by including this.getTablePath(foreignKey) and
foreignKey.referencedColumnNames as arguments. This ensures consistent and
correct foreign key name generation.

src/driver/aurora-mysql/AuroraMysqlQueryRunner.ts [1769-1774]

 if (!foreignKey.name) {
     foreignKey.name = this.connection.namingStrategy.foreignKeyName(
         table,
         foreignKey.columnNames,
+        this.getTablePath(foreignKey),
+        foreignKey.referencedColumnNames,
     )
 }
  • Apply / Chat
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies an inconsistency in the foreignKeyName method call for the Aurora MySQL driver compared to all other drivers modified in this PR. This could lead to incorrect foreign key name generation and subsequent failures, making it a critical fix for driver consistency and correctness.

Medium
  • More

@taichunmin

Copy link
Copy Markdown
Contributor Author

@gioboa conflict resolved. PTAL.

@pkg-pr-new

pkg-pr-new Bot commented Jan 4, 2026

Copy link
Copy Markdown
  • typeorm-sql-js-example

    npm i https://pkg.pr.new/typeorm/typeorm@10744
    

commit: 01ff7f3

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 80.875% (-0.03%) from 80.904%
when pulling 01ff7f3 on taichunmin:dropForeignKey
into ad22c10 on typeorm:master.

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 LGTM

@gioboa
gioboa merged commit 1a98424 into typeorm:master Jan 5, 2026
@taichunmin
taichunmin deleted the dropForeignKey branch January 5, 2026 08:47
Cprakhar pushed a commit to Cprakhar/typeorm that referenced this pull request Jan 7, 2026
mgohin pushed a commit to mgohin/typeorm that referenced this pull request Jan 15, 2026
kranners pushed a commit to kranners/typeorm that referenced this pull request Mar 1, 2026
@pkuczynski pkuczynski added this to the 1.0 milestone Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Error on drop TableForeignKey without name

5 participants