diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-07-29 02:26:42 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-07-29 02:26:42 +0000 |
commit | 9b1ccb29d41e17e386e7811fbfb9ed4308324805 (patch) | |
tree | a1da1fa1193eb90bb31a4355ca74491e899ad859 /lib/sqlalchemy/schema.py | |
parent | 45650694ee3e3d52b96e6c30e1b3176688ad5210 (diff) | |
download | sqlalchemy-9b1ccb29d41e17e386e7811fbfb9ed4308324805.tar.gz |
clearer error for ForeignKey cant locate parent table, [ticket:565]
Diffstat (limited to 'lib/sqlalchemy/schema.py')
-rw-r--r-- | lib/sqlalchemy/schema.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 3faa3b89c..737a992f6 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -147,7 +147,7 @@ class _TableSingleton(sql._FigureVisitName): return table except KeyError: if mustexist: - raise exceptions.ArgumentError("Table '%s.%s' not defined" % (schema, name)) + raise exceptions.ArgumentError("Table '%s' not defined" % (key)) table = type.__call__(self, name, metadata, **kwargs) table._set_parent(metadata) # load column definitions from the database if 'autoload' is defined @@ -728,6 +728,8 @@ class ForeignKey(SchemaItem): schema = None else: (schema,tname,colname) = m.group(1,2,3) + if tname not in parenttable.metadata: + raise exceptions.InvalidRequestError("Could not find table '%s' with which to generate a foreign key" % tname) table = Table(tname, parenttable.metadata, mustexist=True, schema=schema) try: if colname is None: @@ -1108,6 +1110,9 @@ class MetaData(SchemaItem): def __repr__(self): return 'MetaData(%r)' % self.bind + def __contains__(self, key): + return key in self.tables + def __getstate__(self): return {'tables':self.tables, 'casesensitive':self._case_sensitive_setting} |