Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating multiple references in databases for same foreign key #17255

Open
3 of 6 tasks
aamir-alii opened this issue Apr 6, 2024 · 7 comments
Open
3 of 6 tasks

Creating multiple references in databases for same foreign key #17255

aamir-alii opened this issue Apr 6, 2024 · 7 comments

Comments

@aamir-alii
Copy link

Issue Creation Checklist

  • I understand that my issue will be automatically closed if I don't fill in the requested information
  • I have read the contribution guidelines

Add upper case table name in code and dialect server is using lower_case_table_names the issue will be generated.

Bug Description

If I use database name in uppercase and my server is configured with lower_case_table_names then when I specify any relation in my code and the sync option with alter true is on it will create multiple references in table.

Reproducible Example

issue
These all references are created for same reference

What do you expect to happen?

There should be only one reference for each reference

What is actually happening?

There is always creating a new reference each time code restart and sync with alter true is on,

Environment

  • Sequelize version: 6.37.2
  • Node.js version: 20.12.0
  • Database & Version: MYSQL Server 8
  • Connector library & Version: mysql2@3.9.3

Would you be 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 will need guidance.
  • No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
  • No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.

Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.

@aamir-alii aamir-alii added pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: bug labels Apr 6, 2024
@ephys ephys removed the pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet label Apr 6, 2024
@ephys
Copy link
Member

ephys commented Apr 6, 2024

Note for when someone starts working on this task: there are some information about this in #17256

@aamir-alii
Copy link
Author

What if we delete all the constraint of particular table before hand as it is already creating that constraint again look into following code.
code

@ephys
Copy link
Member

ephys commented Apr 16, 2024

sync cannot delete anything unless force is specified, in which case it deletes everything

@aamir-alii
Copy link
Author

sync cannot delete anything unless force is specified, in which case it deletes everything

you don't get my point I want to do something like this

code-example

@aamir-alii
Copy link
Author

Other thing that I have noticed that If we remove reference from a field (and it is still in the model mean we don't remove the field but just the references) it reference in database will not be removed as we are only removing constraint from the field which have some references in the code.

@ephys
Copy link
Member

ephys commented Apr 18, 2024

To explain what I meant in my previous comment: removing constraints is a destructive operation, and the base sync does not do that. I see that in your initial comment you mentioned using the alter option, which could do this kind of operation

@aamir-alii
Copy link
Author

What about if we add name constraint and check if it is not exist with that name and drop if exists
adding name constraint
query-generator

searching for name constraint
model

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants