diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-04-07 11:05:20 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-04-07 11:05:20 -0400 |
commit | 1ae44556907f14f92874f05d05242cb57bb0f855 (patch) | |
tree | 5e744b2c671fdf74be1b613cd5bc145f081fd213 /tests/test_op.py | |
parent | 3d9b1128cd6bf03ecb45003587c0eedfb9552b07 (diff) | |
download | alembic-1ae44556907f14f92874f05d05242cb57bb0f855.tar.gz |
uniquify cols for FK table object
Fixed issue where using a directive such as ``op.create_foreign_key()`` to
create a self-referential constraint on a single table where the same
column were present on both sides (e.g. within a composite foreign key)
would produce an error under SQLAlchemy 2.0 and a warning under SQLAlchemy
1.4 indicating that a duplicate column were being added to a table.
Change-Id: I2a8f5d8def2714792bffcdfb8bf88a5080ec8ce7
Fixes: #1215
Diffstat (limited to 'tests/test_op.py')
-rw-r--r-- | tests/test_op.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/test_op.py b/tests/test_op.py index c483c4a..8ae22a0 100644 --- a/tests/test_op.py +++ b/tests/test_op.py @@ -729,6 +729,21 @@ class OpTest(TestBase): "FOREIGN KEY(foo) REFERENCES t1 (bar)" ) + def test_add_foreign_key_composite_self_referential(self): + """test #1215 + + the same column name is present on both sides. + + """ + context = op_fixture() + op.create_foreign_key( + "fk_test", "t1", "t1", ["foo", "bar"], ["bat", "bar"] + ) + context.assert_( + "ALTER TABLE t1 ADD CONSTRAINT fk_test " + "FOREIGN KEY(foo, bar) REFERENCES t1 (bat, bar)" + ) + def test_add_primary_key_constraint(self): context = op_fixture() op.create_primary_key("pk_test", "t1", ["foo", "bar"]) |