From 05e39b2c6c19d622db42589a626fe5eaffea022e Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Tue, 9 Nov 2010 22:33:20 +0100 Subject: [PATCH] make migrate.changeset.constraint.ForeignKeyConstraint.autoname work with SQLAlchemy 0.5 and 0.6 --- migrate/changeset/constraint.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/migrate/changeset/constraint.py b/migrate/changeset/constraint.py index 34b2d1a..476a456 100644 --- a/migrate/changeset/constraint.py +++ b/migrate/changeset/constraint.py @@ -126,9 +126,17 @@ class ForeignKeyConstraint(ConstraintChangeset, schema.ForeignKeyConstraint): def autoname(self): """Mimic the database's automatic constraint names""" - ret = "%(table)s_%(firstcolumn)s_fkey" % dict( - table=self.table.name, - firstcolumn=self.columns[0],) + 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],) return ret