- changed status to resolved
Improve the error message on ForeignKey to table that does not exist
Issue #565
resolved
betelgeuse@pena ~/python $ python create.py | grep -i for
Traceback (most recent call last):
File "create.py", line 48, in <module>
create_tables(engine)
File "create.py", line 42, in create_tables
metadata.create_all()
File "/usr/lib/python2.5/site-packages/sqlalchemy/schema.py", line 1150, in create_all
connectable.create(self, checkfirst=checkfirst, tables=tables)
File "/usr/lib/python2.5/site-packages/sqlalchemy/engine/base.py", line 691, in create
self._run_visitor(self.dialect.schemagenerator, entity, connection=connection, **kwargs)
File "/usr/lib/python2.5/site-packages/sqlalchemy/engine/base.py", line 721, in _run_visitor
element.accept_visitor(visitorcallable(conn, **kwargs))
File "/usr/lib/python2.5/site-packages/sqlalchemy/schema.py", line 1172, in accept_visitor
visitor.visit_metadata(self)
File "/usr/lib/python2.5/site-packages/sqlalchemy/ansisql.py", line 804, in visit_metadata
collection = [for t in metadata.table_iterator(reverse=False, tables=self.tables) if (not self.checkfirst or not self.dialect.has_table(self.connection, t.name, schema=t.schema))](t)
File "/usr/lib/python2.5/site-packages/sqlalchemy/schema.py", line 1128, in table_iterator
return iter(sorter.sort(reverse=reverse))
File "/usr/lib/python2.5/site-packages/sqlalchemy/sql_util.py", line 33, in sort
self._sorted = self._do_sort()
File "/usr/lib/python2.5/site-packages/sqlalchemy/sql_util.py", line 54, in _do_sort
vis.traverse(table)
File "/usr/lib/python2.5/site-packages/sqlalchemy/sql.py", line 830, in traverse
self.traverse(n)
File "/usr/lib/python2.5/site-packages/sqlalchemy/sql.py", line 830, in traverse
self.traverse(n)
File "/usr/lib/python2.5/site-packages/sqlalchemy/sql.py", line 831, in traverse
obj.accept_visitor(self)
File "/usr/lib/python2.5/site-packages/sqlalchemy/schema.py", line 731, in accept_visitor
visitor.visit_foreign_key(self)
File "/usr/lib/python2.5/site-packages/sqlalchemy/sql_util.py", line 48, in visit_foreign_key
parent_table = fkey.column.table
File "/usr/lib/python2.5/site-packages/sqlalchemy/schema.py", line 726, in <lambda>
column = property(lambda s: s._init_column())
File "/usr/lib/python2.5/site-packages/sqlalchemy/schema.py", line 707, in _init_column
table = Table(tname, parenttable.metadata, mustexist=True, schema=schema)
File "/usr/lib/python2.5/site-packages/sqlalchemy/schema.py", line 155, in __call__
raise exceptions.ArgumentError("Table '%s.%s' not defined" % (schema, name))
sqlalchemy.exceptions.ArgumentError: Table 'None.pkgs' not defined
Code creating the table:
slots_table = Table('slots', metadata,
Column('slot_id', Integer, primary_key=True),
Column('pkg_id', Integer, ForeignKey('pkgs.pkg_id')),
Column('slot', String),
)
Would be helpful to show 'slots' in the error message in this case and maybe ForeignKey too so it's easier to find out where the code is wrong..
Comments (1)
-
repo owner - Log in to comment
9b1ccb29d41e17e386e7811fbfb9ed4308324805