class ForeignKey(DialectKWArgs, SchemaItem): (source)
Defines a dependency between two columns. ``ForeignKey`` is specified as an argument to a :class:`_schema.Column` object, e.g.:: t = Table("remote_table", metadata, Column("remote_id", ForeignKey("main_table.id")) ) Note that ``ForeignKey`` is only a marker object that defines a dependency between two columns. The actual constraint is in all cases represented by the :class:`_schema.ForeignKeyConstraint` object. This object will be generated automatically when a ``ForeignKey`` is associated with a :class:`_schema.Column` which in turn is associated with a :class:`_schema.Table`. Conversely, when :class:`_schema.ForeignKeyConstraint` is applied to a :class:`_schema.Table`, ``ForeignKey`` markers are automatically generated to be present on each associated :class:`_schema.Column`, which are also associated with the constraint object. Note that you cannot define a "composite" foreign key constraint, that is a constraint between a grouping of multiple parent/child columns, using ``ForeignKey`` objects. To define this grouping, the :class:`_schema.ForeignKeyConstraint` object must be used, and applied to the :class:`_schema.Table`. The associated ``ForeignKey`` objects are created automatically. The ``ForeignKey`` objects associated with an individual :class:`_schema.Column` object are available in the `foreign_keys` collection of that column. Further examples of foreign key configuration are in :ref:`metadata_foreignkeys`.
Method | __init__ |
Construct a column-level FOREIGN KEY. |
Method | __repr__ |
Undocumented |
Method | copy |
Undocumented |
Method | get |
Return the :class:`_schema.Column` in the given :class:`_schema.Table` (or any :class:`.FromClause`) referenced by this :class:`_schema.ForeignKey`. |
Method | references |
Return True if the given :class:`_schema.Table` is referenced by this :class:`_schema.ForeignKey`. |
Class Variable | __visit |
Undocumented |
Class Variable | target |
Undocumented |
Instance Variable | comment |
Undocumented |
Instance Variable | constraint |
Undocumented |
Instance Variable | deferrable |
Undocumented |
Instance Variable | info |
Info dictionary associated with the object, allowing user-defined data to be associated with this :class:`.SchemaItem`. |
Instance Variable | initially |
Undocumented |
Instance Variable | link |
Undocumented |
Instance Variable | match |
Undocumented |
Instance Variable | name |
Undocumented |
Instance Variable | ondelete |
Undocumented |
Instance Variable | onupdate |
Undocumented |
Instance Variable | parent |
Undocumented |
Instance Variable | use |
Undocumented |
Property | column |
Return the target :class:`_schema.Column` referenced by this :class:`_schema.ForeignKey`. |
Method | _copy |
Produce a copy of this :class:`_schema.ForeignKey` object. |
Method | _get |
Return a string based 'column specification' for this :class:`_schema.ForeignKey`. |
Method | _link |
Undocumented |
Method | _remove |
Undocumented |
Method | _resolve |
Undocumented |
Method | _resolve |
Undocumented |
Method | _set |
Associate with this SchemaEvent's parent object. |
Method | _set |
Undocumented |
Method | _set |
Undocumented |
Method | _set |
Undocumented |
Method | _table |
Undocumented |
Instance Variable | _colspec |
Undocumented |
Instance Variable | _table |
Undocumented |
Instance Variable | _unresolvable |
Undocumented |
Instance Variable | _unvalidated |
Undocumented |
Property | _column |
parse a string-based _colspec into its component parts. |
Property | _referred |
Undocumented |
Inherited from DialectKWArgs
:
Class Method | argument |
Add a new kind of dialect-specific keyword argument for this class. |
Class Variable | __slots__ |
Undocumented |
Property | dialect |
A collection of keyword arguments specified as dialect-specific options to this construct. |
Property | dialect |
A collection of keyword arguments specified as dialect-specific options to this construct. |
Property | kwargs |
A synonym for :attr:`.DialectKWArgs.dialect_kwargs`. |
Method | _kw |
Undocumented |
Method | _validate |
Undocumented |
Class Variable | _dialect |
Undocumented |
Class Variable | _kw |
Undocumented |
Inherited from SchemaItem
(via DialectKWArgs
):
Class Variable | create |
Undocumented |
Method | _init |
Initialize the list of child items for this SchemaItem. |
Method | _schema |
Undocumented |
Class Variable | _use |
Undocumented |
Inherited from SchemaEventTarget
(via DialectKWArgs
, SchemaItem
):
Class Variable | dispatch |
Undocumented |
Method | _set |
Undocumented |
Inherited from Visitable
(via DialectKWArgs
, SchemaItem
, SchemaEventTarget
, EventTarget
):
Method | __class |
Undocumented |
Method | __init |
Undocumented |
Class Method | _generate |
Undocumented |
Method | _compiler |
Undocumented |
Class Variable | _original |
Undocumented |
_DDLColumnArgument
, _constraint: Optional[ ForeignKeyConstraint]
= None, use_alter: bool
= False, name: _ConstraintNameArgument
= None, onupdate: Optional[ str]
= None, ondelete: Optional[ str]
= None, deferrable: Optional[ bool]
= None, initially: Optional[ str]
= None, link_to_name: bool
= False, match: Optional[ str]
= None, info: Optional[ _InfoType]
= None, comment: Optional[ str]
= None, _unresolvable: bool
= False, **dialect_kw: Any
):
(source)
¶
Construct a column-level FOREIGN KEY. The :class:`_schema.ForeignKey` object when constructed generates a :class:`_schema.ForeignKeyConstraint` which is associated with the parent :class:`_schema.Table` object's collection of constraints. :param column: A single target column for the key relationship. A :class:`_schema.Column` object or a column name as a string: ``tablename.columnkey`` or ``schema.tablename.columnkey``. ``columnkey`` is the ``key`` which has been assigned to the column (defaults to the column name itself), unless ``link_to_name`` is ``True`` in which case the rendered name of the column is used. :param name: Optional string. An in-database name for the key if `constraint` is not provided. :param onupdate: Optional string. If set, emit ON UPDATE <value> when issuing DDL for this constraint. Typical values include CASCADE, DELETE and RESTRICT. :param ondelete: Optional string. If set, emit ON DELETE <value> when issuing DDL for this constraint. Typical values include CASCADE, DELETE and RESTRICT. :param deferrable: Optional bool. If set, emit DEFERRABLE or NOT DEFERRABLE when issuing DDL for this constraint. :param initially: Optional string. If set, emit INITIALLY <value> when issuing DDL for this constraint. :param link_to_name: if True, the string name given in ``column`` is the rendered name of the referenced column, not its locally assigned ``key``. :param use_alter: passed to the underlying :class:`_schema.ForeignKeyConstraint` to indicate the constraint should be generated/dropped externally from the CREATE TABLE/ DROP TABLE statement. See :paramref:`_schema.ForeignKeyConstraint.use_alter` for further description. .. seealso:: :paramref:`_schema.ForeignKeyConstraint.use_alter` :ref:`use_alter` :param match: Optional string. If set, emit MATCH <value> when issuing DDL for this constraint. Typical values include SIMPLE, PARTIAL and FULL. :param info: Optional data dictionary which will be populated into the :attr:`.SchemaItem.info` attribute of this object. .. versionadded:: 1.0.0 :param comment: Optional string that will render an SQL comment on foreign key constraint creation. .. versionadded:: 2.0 :param \**dialect_kw: Additional keyword arguments are dialect specific, and passed in the form ``<dialectname>_<argname>``. The arguments are ultimately handled by a corresponding :class:`_schema.ForeignKeyConstraint`. See the documentation regarding an individual dialect at :ref:`dialect_toplevel` for detail on documented arguments. .. versionadded:: 0.9.2
def copy(self, *, schema:
Optional[ str]
= None, **kw: Any
) -> ForeignKey
:
(source)
¶
Undocumented
Return the :class:`_schema.Column` in the given :class:`_schema.Table` (or any :class:`.FromClause`) referenced by this :class:`_schema.ForeignKey`. Returns None if this :class:`_schema.ForeignKey` does not reference the given :class:`_schema.Table`.
sqlalchemy.sql.schema.SchemaItem.info
Info dictionary associated with the object, allowing user-defined data to be associated with this :class:`.SchemaItem`. The dictionary is automatically generated when first accessed. It can also be specified in the constructor of some objects, such as :class:`_schema.Table` and :class:`_schema.Column`.
Return the target :class:`_schema.Column` referenced by this :class:`_schema.ForeignKey`. If no target column has been established, an exception is raised.
Produce a copy of this :class:`_schema.ForeignKey` object. The new :class:`_schema.ForeignKey` will not be bound to any :class:`_schema.Column`. This method is usually used by the internal copy procedures of :class:`_schema.Column`, :class:`_schema.Table`, and :class:`_schema.MetaData`. :param schema: The returned :class:`_schema.ForeignKey` will reference the original table and column name, qualified by the given string schema name.
Optional[ Union[ str, Literal[ SchemaConst.RETAIN_SCHEMA, SchemaConst.BLANK_SCHEMA]]]
= None, table_name: Optional[ str]
= None, _is_copy: bool
= False) -> str
:
(source)
¶
Return a string based 'column specification' for this :class:`_schema.ForeignKey`. This is usually the equivalent of the string-based "tablename.colname" argument first passed to the object's constructor.
Table
, table: Table
, colname: Optional[ str]
) -> Column[ Any]
:
(source)
¶
Undocumented