Return a copy of this :class:`_schema.Table` associated with a different :class:`_schema.MetaData`. E.g.:: m1 = MetaData() user = Table("user", m1, Column("id", Integer, primary_key=True)) m2 = MetaData() user_copy = user.to_metadat
(
self,
metadata: MetaData,
schema: Union[str, Literal[SchemaConst.RETAIN_SCHEMA]] = RETAIN_SCHEMA,
referred_schema_fn: Optional[
Callable[
[Table, Optional[str], ForeignKeyConstraint, Optional[str]],
Optional[str],
]
] = None,
name: Optional[str] = None,
)
| 1598 | ) |
| 1599 | |
| 1600 | def to_metadata( |
| 1601 | self, |
| 1602 | metadata: MetaData, |
| 1603 | schema: Union[str, Literal[SchemaConst.RETAIN_SCHEMA]] = RETAIN_SCHEMA, |
| 1604 | referred_schema_fn: Optional[ |
| 1605 | Callable[ |
| 1606 | [Table, Optional[str], ForeignKeyConstraint, Optional[str]], |
| 1607 | Optional[str], |
| 1608 | ] |
| 1609 | ] = None, |
| 1610 | name: Optional[str] = None, |
| 1611 | ) -> Table[_ColCC_co]: |
| 1612 | class="st">"""Return a copy of this :class:`_schema.Table` associated with a |
| 1613 | different :class:`_schema.MetaData`. |
| 1614 | |
| 1615 | E.g.:: |
| 1616 | |
| 1617 | m1 = MetaData() |
| 1618 | |
| 1619 | user = Table(class="st">"user", m1, Column(class="st">"id", Integer, primary_key=True)) |
| 1620 | |
| 1621 | m2 = MetaData() |
| 1622 | user_copy = user.to_metadata(m2) |
| 1623 | |
| 1624 | .. versionchanged:: 1.4 The :meth:`_schema.Table.to_metadata` function |
| 1625 | was renamed from :meth:`_schema.Table.tometadata`. |
| 1626 | |
| 1627 | |
| 1628 | :param metadata: Target :class:`_schema.MetaData` object, |
| 1629 | into which the |
| 1630 | new :class:`_schema.Table` object will be created. |
| 1631 | |
| 1632 | :param schema: optional string name indicating the target schema. |
| 1633 | Defaults to the special symbol :attr:`.RETAIN_SCHEMA` which indicates |
| 1634 | that no change to the schema name should be made in the new |
| 1635 | :class:`_schema.Table`. If set to a string name, the new |
| 1636 | :class:`_schema.Table` |
| 1637 | will have this new name as the ``.schema``. If set to ``None``, the |
| 1638 | schema will be set to that of the schema set on the target |
| 1639 | :class:`_schema.MetaData`, which is typically ``None`` as well, |
| 1640 | unless |
| 1641 | set explicitly:: |
| 1642 | |
| 1643 | m2 = MetaData(schema=class="st">"newschema") |
| 1644 | |
| 1645 | class="cm"># user_copy_one will have class="st">"newschema" as the schema name |
| 1646 | user_copy_one = user.to_metadata(m2, schema=None) |
| 1647 | |
| 1648 | m3 = MetaData() class="cm"># schema defaults to None |
| 1649 | |
| 1650 | class="cm"># user_copy_two will have None as the schema name |
| 1651 | user_copy_two = user.to_metadata(m3, schema=None) |
| 1652 | |
| 1653 | :param referred_schema_fn: optional callable which can be supplied |
| 1654 | in order to provide for the schema name that should be assigned |
| 1655 | to the referenced table of a :class:`_schema.ForeignKeyConstraint`. |
| 1656 | The callable accepts this parent :class:`_schema.Table`, the |
| 1657 | target schema that we are changing to, the |