> 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.
Sorry for not replying for a month.
I'm trying to produce a test case using simple tables. I use two
MetaDatas but what I get is
sqlalchemy.exceptions.NoReferencedTableError: Could not find table 'A'
with which to generate a foreign key
In production code I use foreign keys between tables in different
metadatas (I use one MetaData per "component"). Is it ok and should
work?
Here is the complete code:
#!/usr/bin/python
from sqlalchemy import Table, Column, Integer, Text, MetaData,
ForeignKey, Date, DateTime, Float
from sqlalchemy.engine import create_engine
from sqlalchemy.orm import mapper, relation, backref
engine = create_engine('sqlite://')
metadata_1 = MetaData()
metadata_2 = MetaData()
def _cloneToSND(table, metadata):
return Table('SND_' + table.name, metadata,
*([c.copy() for c in table.columns] + \
[c.copy() for c in table.constraints]))
tableA = Table('A', metadata_1,
Column('id', Integer, primary_key=True))
tableB = Table('B', metadata_1,
Column('id', Integer, primary_key=True),
Column('a_id', Integer, ForeignKey(tableA.c.id),
nullable=True, index=True))
tableC = Table('C', metadata_2,
Column('id', Integer, primary_key=True),
Column('a_id', Integer, ForeignKey(tableA.c.id),
nullable=True, index=True))
#Column('b_id', Integer, ForeignKey(tableB.c.id),
nullable=True, index=True))
tableSND_A = _cloneToSND(tableA, metadata_1)
tableSND_B = _cloneToSND(tableB, metadata_1)
tableSND_C = _cloneToSND(tableC, metadata_2)
if __name__ == '__main__':
metadata_1.create_all(bind=engine)
metadata_2.create_all(bind=engine)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---