.. changelog::
:version: 1.0.14
+ .. change::
+ :tags: bug, sql
+ :tickets: 3721
+
+ Fixed bug whereby :meth:`.Table.tometadata` would make a duplicate
+ :class:`.UniqueConstraint` for each :class:`.Column` object that
+ featured the ``unique=True`` parameter.
+
.. change::
:tags: bug, engine, postgresql
:tickets: 3716
schema if referred_schema == self.schema else None)
table.append_constraint(
c.copy(schema=fk_constraint_schema, target_table=table))
-
elif not c._type_bound:
+ # skip unique constraints that would be generated
+ # by the 'unique' flag on Column
+ if isinstance(c, UniqueConstraint) and \
+ len(c.columns) == 1 and \
+ list(c.columns)[0].unique:
+ continue
+
table.append_constraint(
c.copy(schema=schema, target_table=table))
for index in self.indexes:
eq_(str(table_c.join(table2_c).onclause),
'mytable.myid = othertable.myid')
+ def test_unique_true_flag(self):
+ meta = MetaData()
+
+ table = Table('mytable', meta, Column('x', Integer, unique=True))
+
+ m2 = MetaData()
+
+ t2 = table.tometadata(m2)
+
+ eq_(
+ len([
+ const for const
+ in t2.constraints
+ if isinstance(const, UniqueConstraint)]),
+ 1
+ )
+
+ def test_index_true_flag(self):
+ meta = MetaData()
+
+ table = Table('mytable', meta, Column('x', Integer, index=True))
+
+ m2 = MetaData()
+
+ t2 = table.tometadata(m2)
+
+ eq_(len(t2.indexes), 1)
+
class InfoTest(fixtures.TestBase):
def test_metadata_info(self):