tometadata() doubles up unique constraint for unique=True
from sqlalchemy import Table, MetaData, Column, Integer
m1 = MetaData()
t1 = Table(
't', m1, Column('id', Integer, unique=True)
)
m2 = MetaData()
t2 = t1.tometadata(m2)
print t2.constraints
output:
set([UniqueConstraint(Column('id', Integer(), table=<t>)), PrimaryKeyConstraint(), UniqueConstraint(Column('id', Integer(), table=<t>))])
Comments (3)
-
reporter -
reporter - changed status to resolved
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→ <<cset afb466fb8bd9>>
-
reporter 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(cherry picked from commit afb466fb8bd9c2f8709e79fd0fce422b83ff1d6b)→ <<cset d318139fdc4c>>
- Log in to comment
https://gerrit.sqlalchemy.org/#/q/Ie622ee912a6fb8bf0ea900a8b09d78c7ebc79fc0