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
Models with cyclic foreign keys and ENUM-typed fields can't be synced in Postgres #15522
Open
3 of 6 tasks
Labels
Comments
francofrizzo
added
pending-approval
Bug reports that have not been verified yet, or feature requests that have not been accepted yet
type: bug
labels
Jan 3, 2023
I can confirm this on sequelize/test/integration/model/sync.test.js Lines 527 to 555 in 989713a
I think part of the fix should be in |
WikiRik
removed
the
pending-approval
Bug reports that have not been verified yet, or feature requests that have not been accepted yet
label
Jan 3, 2023
This is a variant of #7649. The cause is the same, but we can add this test to the new suite to make sure |
8 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue Creation Checklist
Bug Description
In PostgreSQL, when there is a circular dependency between models (following foreign keys) and at least some model in the database has an ENUM-typed property, calls to
sequelize.sync()
will fail, as the enum type is attempted to be created twice.This bug seems to have been introduced in v6.20.0, when support for cyclic foreign keys was added. The implementation synchronizes the models twice, first to create the tables, and then to create the foreign keys. Both runs are attempting to create the types for the ENUM-typed fields, which is not an idempotent operation.
Reproducible Example
Here is the link to the SSCCE for this issue: https://github.com/francofrizzo/sequelize-sscce-cyclic-associations
What do you expect to happen?
Models should be correctly synced when
sequelize.sync()
is called.What is actually happening?
A
SequelizeDatabaseError
is thrown, indicating thattype "enum_<model>_<field>" already exists
.Environment
Would you be willing to resolve this issue by submitting a Pull Request?
Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.
The text was updated successfully, but these errors were encountered: