class documentation

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_name__ 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_to_name Undocumented
Instance Variable match Undocumented
Instance Variable ondelete Undocumented
Instance Variable onupdate Undocumented
Instance Variable use_alter Undocumented
Property column_keys Return a list of string keys representing the local columns in this :class:`_schema.ForeignKeyConstraint`.
Property referred_table The :class:`_schema.Table` object to which this :class:`_schema.ForeignKeyConstraint` references.
Method _append_element Undocumented
Method _copy Undocumented
Method _set_parent Associate with this SchemaEvent's parent object.
Method _validate_dest_table Undocumented
Property _col_description Undocumented
Property _elements Undocumented
Property _referred_schema Undocumented

Inherited from ColumnCollectionConstraint:

Method __contains__ Undocumented
Method __iter__ Undocumented
Method __len__ Undocumented
Method contains_column Return True if this constraint contains the given column.

Inherited from ColumnCollectionMixin (via ColumnCollectionConstraint):

Property c Undocumented
Method _check_attach Undocumented
Method _col_expressions Undocumented
Method _set_parent_with_dispatch Undocumented
Class Variable _allow_multiple_tables Undocumented
Instance Variable _cols_wo_table Undocumented
Instance Variable _column_flag Undocumented
Instance Variable _columns Undocumented
Instance Variable _pending_colargs 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_create_for_compiler Undocumented
Class Variable _creation_order Undocumented
Instance Variable _create_rule Undocumented
Instance Variable _type_bound Undocumented

Inherited from DialectKWArgs (via ColumnCollectionConstraint, ColumnCollectionMixin, Constraint):

Class Method argument_for Add a new kind of dialect-specific keyword argument for this class.
Class Variable __slots__ Undocumented
Property dialect_kwargs A collection of keyword arguments specified as dialect-specific options to this construct.
Property dialect_options A collection of keyword arguments specified as dialect-specific options to this construct.
Property kwargs A synonym for :attr:`.DialectKWArgs.dialect_kwargs`.
Method _kw_reg_for_dialect_cls Undocumented
Method _validate_dialect_kwargs Undocumented
Class Variable _dialect_kwargs_traverse_internals Undocumented
Class Variable _kw_registry Undocumented

Inherited from HasConditionalDDL (via ColumnCollectionConstraint, ColumnCollectionMixin, Constraint, DialectKWArgs):

Method ddl_if apply a conditional DDL rule to this schema item.
Instance Variable _ddl_if Undocumented

Inherited from SchemaItem (via ColumnCollectionConstraint, ColumnCollectionMixin, Constraint, DialectKWArgs, HasConditionalDDL):

Method __repr__ Undocumented
Class Variable create_drop_stringify_dialect Undocumented
Method _init_items Initialize the list of child items for this SchemaItem.
Method _schema_item_copy Undocumented
Class Variable _use_schema_map 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_getitem__ Undocumented
Method __init_subclass__ Undocumented
Class Method _generate_compiler_dispatch Undocumented
Method _compiler_dispatch Undocumented
Class Variable _original_compiler_dispatch Undocumented
def __init__(self, columns: _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

@util.deprecated('1.4', 'The :meth:`_schema.ForeignKeyConstraint.copy` method is deprecated and will be removed in a future release.')
def copy(self, *, schema: Optional[str] = None, target_table: Optional[Table] = None, **kw: Any) -> ForeignKeyConstraint: (source)

A :class:`_expression.ColumnCollection` representing the set of columns for this constraint.

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.

link_to_name = (source)

Undocumented

Undocumented

ondelete = (source)

Undocumented

onupdate = (source)

Undocumented

use_alter = (source)

Undocumented

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

@property
referred_table: Table = (source)

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

def _append_element(self, column: Column[Any], fk: ForeignKey): (source)

Undocumented

def _copy(self, *, schema: Optional[str] = None, target_table: Optional[Table] = None, **kw: Any) -> ForeignKeyConstraint: (source)
def _set_parent(self, parent: SchemaEventTarget, **kw: Any): (source)

Associate with this SchemaEvent's parent object.

def _validate_dest_table(self, table: Table): (source)

Undocumented

@property
_col_description: str = (source)

Undocumented

@property
_elements: util.OrderedDict[str, ForeignKey] = (source)

Undocumented

@property
_referred_schema: Optional[str] = (source)

Undocumented