t1 = sa_schema.Table(
source,
m,
- *[sa_schema.Column(n, NULLTYPE) for n in t1_cols],
+ *[
+ sa_schema.Column(n, NULLTYPE)
+ for n in util.unique_list(t1_cols)
+ ],
schema=source_schema,
)
--- /dev/null
+.. change::
+ :tags: bug, operations
+ :tickets: 1215
+
+ 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.
"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"])