diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-06-02 13:52:27 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-06-02 13:54:07 -0400 |
commit | afb466fb8bd9c2f8709e79fd0fce422b83ff1d6b (patch) | |
tree | 651408218157fb0ef6e75af278b4f0d1135eb177 /lib/sqlalchemy/sql/schema.py | |
parent | 7a4aa46ae49f3ddcdadd4f3f10ef9cbce1fbf9aa (diff) | |
download | sqlalchemy-afb466fb8bd9c2f8709e79fd0fce422b83ff1d6b.tar.gz |
Skip UniqueConstraint marked by unique=True in tometadata
Fixes an issue where a Column would be copied with unique=True
and at the same time the UniqueConstraint would also be copied,
leading to duplicate UniqueConstraints in the target table,
when tometadata() is used. Imitates the same logic used
by index=True/Index to avoid duplicates. For some reason
a fix was implemented for Index long ago but never for
UniqueConstraint.
Change-Id: Ie622ee912a6fb8bf0ea900a8b09d78c7ebc79fc0
Fixes: #3721
Diffstat (limited to 'lib/sqlalchemy/sql/schema.py')
-rw-r--r-- | lib/sqlalchemy/sql/schema.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index 64692644c..cb01a49e3 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -852,8 +852,14 @@ class Table(DialectKWArgs, SchemaItem, TableClause): 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: |