to further identify columns that are "equivalent".
\**kw may specify 'ignore_nonexistent_tables' to ignore foreign keys
- whose tables are not yet configured.
+ whose tables are not yet configured, or columns that aren't yet present.
This function is primarily used to determine the most minimal "primary key"
from a selectable, by reducing the set of primary key columns present
continue
try:
fk_col = fk.column
+ except exc.NoReferencedColumnError:
+ # TODO: add specific coverage here
+ # to test/sql/test_selectable ReduceTest
+ if ignore_nonexistent_tables:
+ continue
+ else:
+ raise
except exc.NoReferencedTableError:
+ # TODO: add specific coverage here
+ # to test/sql/test_selectable ReduceTest
if ignore_nonexistent_tables:
continue
else:
from sqlalchemy.ext.declarative import _MapperConfig
_MapperConfig.configs.clear()
+class DeferredReflectPKFKTest(DeferredReflectBase):
+ @classmethod
+ def define_tables(cls, metadata):
+ Table("a", metadata,
+ Column('id', Integer,
+ primary_key=True, test_needs_autoincrement=True),
+ )
+ Table("b", metadata,
+ Column('id', Integer,
+ ForeignKey('a.id'),
+ primary_key=True),
+ Column('x', Integer, primary_key=True)
+ )
+
+ def test_pk_fk(self):
+ class B(decl.DeferredReflection, fixtures.ComparableEntity,
+ Base):
+ __tablename__ = 'b'
+ a = relationship("A")
+
+ class A(decl.DeferredReflection, fixtures.ComparableEntity,
+ Base):
+ __tablename__ = 'a'
+
+ decl.DeferredReflection.prepare(testing.db)
+
class DeferredReflectionTest(DeferredReflectBase):
@classmethod