make migrate.changeset.constraint.ForeignKeyConstraint.autoname work

with SQLAlchemy 0.5 and 0.6
This commit is contained in:
Jan Dittberner 2010-11-09 22:33:20 +01:00
parent a3ae4baa29
commit 05e39b2c6c

View File

@ -126,6 +126,14 @@ class ForeignKeyConstraint(ConstraintChangeset, schema.ForeignKeyConstraint):
def autoname(self):
"""Mimic the database's automatic constraint names"""
if hasattr(self.columns, 'keys'):
# SA <= 0.5
firstcol = self.columns[self.columns.keys()[0]]
ret = "%(table)s_%(firstcolumn)s_fkey" % dict(
table=firstcol.table.name,
firstcolumn=firstcol.name,)
else:
# SA >= 0.6
ret = "%(table)s_%(firstcolumn)s_fkey" % dict(
table=self.table.name,
firstcolumn=self.columns[0],)