class ForeignKeyConstraint(ColumnCollectionConstraint): (source)
A table-level FOREIGN KEY constraint. Defines a single column or composite FOREIGN KEY ... REFERENCES constraint. For a no-frills, single column foreign key, adding a :class:`_schema.ForeignKey` to the definition of a :class:`_schema.Column` is a shorthand equivalent for an unnamed, single column :class:`_schema.ForeignKeyConstraint`. Examples of foreign key configuration are in :ref:`metadata_foreignkeys`.
Method | __init__ |
Construct a composite-capable FOREIGN KEY. |
Method | copy |
Undocumented |
Class Variable | __visit |
Undocumented |
Class Variable | columns |
A :class:`_expression.ColumnCollection` representing the set of columns for this constraint. |
Instance Variable | elements |
A sequence of :class:`_schema.ForeignKey` objects. |
Instance Variable | link |
Undocumented |
Instance Variable | match |
Undocumented |
Instance Variable | ondelete |
Undocumented |
Instance Variable | onupdate |
Undocumented |
Instance Variable | use |
Undocumented |
Property | column |
Return a list of string keys representing the local columns in this :class:`_schema.ForeignKeyConstraint`. |
Property | referred |
The :class:`_schema.Table` object to which this :class:`_schema.ForeignKeyConstraint` references. |
Method | _append |
Undocumented |
Method | _copy |
Undocumented |
Method | _set |
Associate with this SchemaEvent's parent object. |
Method | _validate |
Undocumented |
Property | _col |
Undocumented |
Property | _elements |
Undocumented |
Property | _referred |
Undocumented |
Inherited from ColumnCollectionConstraint
:
Method | __contains__ |
Undocumented |
Method | __iter__ |
Undocumented |
Method | __len__ |
Undocumented |
Method | contains |
Return True if this constraint contains the given column. |
Inherited from ColumnCollectionMixin
(via ColumnCollectionConstraint
):
Property | c |
Undocumented |
Method | _check |
Undocumented |
Method | _col |
Undocumented |
Method | _set |
Undocumented |
Class Variable | _allow |
Undocumented |
Instance Variable | _cols |
Undocumented |
Instance Variable | _column |
Undocumented |
Instance Variable | _columns |
Undocumented |
Instance Variable | _pending |
Undocumented |
Inherited from Constraint
(via ColumnCollectionConstraint
, ColumnCollectionMixin
):
Instance Variable | comment |
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 | name |
Undocumented |
Instance Variable | parent |
Undocumented |
Property | table |
Undocumented |
Method | _should |
Undocumented |
Class Variable | _creation |
Undocumented |
Instance Variable | _create |
Undocumented |
Instance Variable | _type |
Undocumented |
Inherited from DialectKWArgs
(via ColumnCollectionConstraint
, ColumnCollectionMixin
, Constraint
):
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 HasConditionalDDL
(via ColumnCollectionConstraint
, ColumnCollectionMixin
, Constraint
, DialectKWArgs
):
Method | ddl |
apply a conditional DDL rule to this schema item. |
Instance Variable | _ddl |
Undocumented |
Inherited from SchemaItem
(via ColumnCollectionConstraint
, ColumnCollectionMixin
, Constraint
, DialectKWArgs
, HasConditionalDDL
):
Method | __repr__ |
Undocumented |
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 ColumnCollectionConstraint
, ColumnCollectionMixin
, Constraint
, DialectKWArgs
, HasConditionalDDL
, SchemaItem
):
Class Variable | dispatch |
Undocumented |
Inherited from Visitable
(via ColumnCollectionConstraint
, ColumnCollectionMixin
, Constraint
, DialectKWArgs
, HasConditionalDDL
, SchemaItem
, SchemaEventTarget
, EventTarget
):
Method | __class |
Undocumented |
Method | __init |
Undocumented |
Class Method | _generate |
Undocumented |
Method | _compiler |
Undocumented |
Class Variable | _original |
Undocumented |
_typing_Sequence[ _DDLColumnArgument]
, refcolumns: _typing_Sequence[ _DDLColumnArgument]
, name: _ConstraintNameArgument
= None, onupdate: Optional[ str]
= None, ondelete: Optional[ str]
= None, deferrable: Optional[ bool]
= None, initially: Optional[ str]
= None, use_alter: bool
= False, link_to_name: bool
= False, match: Optional[ str]
= None, table: Optional[ Table]
= None, info: Optional[ _InfoType]
= None, comment: Optional[ str]
= None, **dialect_kw: Any
):
(source)
¶
Construct a composite-capable FOREIGN KEY. :param columns: A sequence of local column names. The named columns must be defined and present in the parent Table. The names should match the ``key`` given to each column (defaults to the name) unless ``link_to_name`` is True. :param refcolumns: A sequence of foreign column names or Column objects. The columns must all be located within the same Table. :param name: Optional, the in-database name of the key. :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: If True, do not emit the DDL for this constraint as part of the CREATE TABLE definition. Instead, generate it via an ALTER TABLE statement issued after the full collection of tables have been created, and drop it via an ALTER TABLE statement before the full collection of tables are dropped. The use of :paramref:`_schema.ForeignKeyConstraint.use_alter` is particularly geared towards the case where two or more tables are established within a mutually-dependent foreign key constraint relationship; however, the :meth:`_schema.MetaData.create_all` and :meth:`_schema.MetaData.drop_all` methods will perform this resolution automatically, so the flag is normally not needed. .. versionchanged:: 1.0.0 Automatic resolution of foreign key cycles has been added, removing the need to use the :paramref:`_schema.ForeignKeyConstraint.use_alter` in typical use cases. .. seealso:: :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>``. 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, target_table: Optional[ Table]
= None, **kw: Any
) -> ForeignKeyConstraint
:
(source)
¶
Undocumented
A sequence of :class:`_schema.ForeignKey` objects. Each :class:`_schema.ForeignKey` represents a single referring column/referred column pair. This collection is intended to be read-only.
Return a list of string keys representing the local columns in this :class:`_schema.ForeignKeyConstraint`. This list is either the original string arguments sent to the constructor of the :class:`_schema.ForeignKeyConstraint`, or if the constraint has been initialized with :class:`_schema.Column` objects, is the string ``.key`` of each element. .. versionadded:: 1.0.0
The :class:`_schema.Table` object to which this :class:`_schema.ForeignKeyConstraint` references. This is a dynamically calculated attribute which may not be available if the constraint and/or parent table is not yet associated with a metadata collection that contains the referred table. .. versionadded:: 1.0.0
Optional[ str]
= None, target_table: Optional[ Table]
= None, **kw: Any
) -> ForeignKeyConstraint
:
(source)
¶
Undocumented