-
-
Notifications
You must be signed in to change notification settings - Fork 250
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 a self-referential foreign key with composite primary key throws a SA DuplicateColumnError #1215
Comments
Hi It would be helpful if the complete stack strace was posted. I'll try reproducing. |
Thanks for the hard work! Sure, I added another stack trace which is produced by the |
this is likely some "we have to check for the column before adding it" thing in schemaobj.py |
it's just we have tests for this already and they do not produce a warning or error. so. |
oh. same name col in both sides. duh |
Mike Bayer has proposed a fix for this issue in the main branch: uniquify cols for FK table object https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/4552 |
Describe the bug
With SA 2, creating a self-referential foreign key with composite primary key throws a SQLAlchemy DuplicateColumnError. In more general terms, an error is thrown if self-referential foreign key has at least one same column as "source" and "target" column.
Expected behavior
The foreign key is created without an error. Works with SA 1.4, although, a deprecation warning is raised.
To Reproduce
Create a migration with the code below and run it.
Error
Stacktrace when running migration with custom Pytest setup that resets DB & runs migrations.
Stacktrace when running cli
alembic upgrade head
Versions.
Additional context
One fix is to remove duplicates from the list of columns in here https://github.com/sqlalchemy/alembic/blob/main/alembic/operations/schemaobj.py#L79
t1_cols = set(local_cols + remote_cols)
, but I'm lacking Alembic/SA knowledge to know if this breaks something else.Have a nice day!
The text was updated successfully, but these errors were encountered: