summaryrefslogtreecommitdiff
path: root/migrate/changeset/constraint.py
diff options
context:
space:
mode:
authorJan Dittberner <jan@dittberner.info>2010-11-09 22:33:20 +0100
committerJan Dittberner <jan@dittberner.info>2010-11-09 22:33:20 +0100
commit05e39b2c6c19d622db42589a626fe5eaffea022e (patch)
tree111e15d982b12524cb0d4afb9c1ab882dda6006e /migrate/changeset/constraint.py
parenta3ae4baa299eb9b6240be1e2aa44eee42a8be76a (diff)
downloadsqlalchemy-migrate-05e39b2c6c19d622db42589a626fe5eaffea022e.tar.gz
make migrate.changeset.constraint.ForeignKeyConstraint.autoname work
with SQLAlchemy 0.5 and 0.6
Diffstat (limited to 'migrate/changeset/constraint.py')
-rw-r--r--migrate/changeset/constraint.py14
1 files 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