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,9 +126,17 @@ class ForeignKeyConstraint(ConstraintChangeset, schema.ForeignKeyConstraint):
def autoname(self): def autoname(self):
"""Mimic the database's automatic constraint names""" """Mimic the database's automatic constraint names"""
ret = "%(table)s_%(firstcolumn)s_fkey" % dict( if hasattr(self.columns, 'keys'):
table=self.table.name, # SA <= 0.5
firstcolumn=self.columns[0],) 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],)
return ret return ret