From 12f126f30bbad323b7e18cb704836252f3669e0f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 17 Apr 2007 21:28:55 +0000 Subject: [PATCH] slight cleanup for #498 --- lib/sqlalchemy/schema.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index ff835cec93..a0dd287e33 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -707,12 +707,15 @@ class ForeignKey(SchemaItem): table = Table(tname, parenttable.metadata, mustexist=True, schema=schema) try: if colname is None: + # colname is None in the case that ForeignKey argument was specified + # as table name only, in which case we match the column name to the same + # column on the parent. key = self.parent self._column = table.c[self.parent.key] else: self._column = table.c[colname] except KeyError, e: - raise exceptions.ArgumentError("Could not create ForeignKey '%s' on table '%s': table '%s' has no column named '%s'" % (self._colspec, parenttable.name, table.name, e.args[0])) + raise exceptions.ArgumentError("Could not create ForeignKey '%s' on table '%s': table '%s' has no column named '%s'" % (self._colspec, parenttable.name, table.name, str(e))) else: self._column = self._colspec # propigate TypeEngine to parent if it didnt have one -- 2.47.2