On Jun 12, 2008, at 4:05 AM, Artur Siekielski wrote:
Hi.
I want to have two Table definitions in one MetaData which are the
same except the name of the second one has SND_ prefix. To avoid
duplication of schema definition I looked at Table.tometadata() source
and created the following function:
def _cloneToSND(table, metadata):
return Table('SND_' + table.name, metadata, *([c.copy() for c in
table.columns] + \
[c.copy() for c in table.constraints]))
But calling metadata.create_all() ends with error:
metadata.create_all(e)
File /usr/share/python2.5/site-packages/SQLAlchemy-0.4.6dev_r4841-
py2.5.egg/sqlalchemy/schema.py, line 1582, in create_all
bind.create(self, checkfirst=checkfirst, tables=tables)
File /usr/share/python2.5/site-packages/SQLAlchemy-0.4.6dev_r4841-
py2.5.egg/sqlalchemy/engine/base.py, line 1139, in create
self._run_visitor(self.dialect.schemagenerator, entity,
connection=connection, **kwargs)
File /usr/share/python2.5/site-packages/SQLAlchemy-0.4.6dev_r4841-
py2.5.egg/sqlalchemy/engine/base.py, line 1168, in _run_visitor
visitorcallable(self.dialect, conn, **kwargs).traverse(element)
File /usr/share/python2.5/site-packages/SQLAlchemy-0.4.6dev_r4841-
py2.5.egg/sqlalchemy/sql/visitors.py, line 75, in traverse
return self._non_cloned_traversal(obj)
File /usr/share/python2.5/site-packages/SQLAlchemy-0.4.6dev_r4841-
py2.5.egg/sqlalchemy/sql/visitors.py, line 134, in
_non_cloned_traversal
self.traverse_single(target)
File /usr/share/python2.5/site-packages/SQLAlchemy-0.4.6dev_r4841-
py2.5.egg/sqlalchemy/sql/visitors.py, line 35, in traverse_single
return meth(obj, **kwargs)
File /usr/share/python2.5/site-packages/SQLAlchemy-0.4.6dev_r4841-
py2.5.egg/sqlalchemy/sql/compiler.py, line 756, in visit_metadata
collection = [t 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))]
File /usr/share/python2.5/site-packages/SQLAlchemy-0.4.6dev_r4841-
py2.5.egg/sqlalchemy/schema.py, line 1456, in table_iterator
return iter(sort_tables(tables, reverse=reverse))
File /usr/share/python2.5/site-packages/SQLAlchemy-0.4.6dev_r4841-
py2.5.egg/sqlalchemy/sql/util.py, line 21, in sort_tables
vis.traverse(table)
File /usr/share/python2.5/site-packages/SQLAlchemy-0.4.6dev_r4841-
py2.5.egg/sqlalchemy/sql/visitors.py, line 75, in traverse
return self._non_cloned_traversal(obj)
File /usr/share/python2.5/site-packages/SQLAlchemy-0.4.6dev_r4841-
py2.5.egg/sqlalchemy/sql/visitors.py, line 134, in
_non_cloned_traversal
self.traverse_single(target)
File /usr/share/python2.5/site-packages/SQLAlchemy-0.4.6dev_r4841-
py2.5.egg/sqlalchemy/sql/visitors.py, line 35, in traverse_single
return meth(obj, **kwargs)
File /usr/share/python2.5/site-packages/SQLAlchemy-0.4.6dev_r4841-
py2.5.egg/sqlalchemy/sql/util.py, line 15, in visit_foreign_key
parent_table = fkey.column.table
File /usr/share/python2.5/site-packages/SQLAlchemy-0.4.6dev_r4841-
py2.5.egg/sqlalchemy/schema.py, line 788, in column
foreign key % tname)
sqlalchemy.exceptions.NoReferencedTableError: Could not find table
'ObjectType' with which to generate a foreign key
The first table (without SND_ prefix) was created successfully. Any
ideas how to achieve my goal?
send along a test case that includes whatever ForeignKey references to/
from ObjectType might be involved here.My initial guess might be
to lose the constraints.copy() section since each Column.copy() will
contain a copied ForeignKey inside of it. copy() has only been used
by the to_metadata() method up til this point.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---