class ForeignKeyConstraint(ColumnCollectionConstraint):
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
_schema.ForeignKey
to the definition of a _schema.Column
is a
shorthand equivalent for an unnamed, single column
_schema.ForeignKeyConstraint
.
Examples of foreign key configuration are in :ref:`metadata_foreignkeys`.
Method | __init__ |
Construct a composite-capable FOREIGN KEY. |
Method | _append_element |
Undocumented |
Method | _copy |
Undocumented |
Method | _set_parent |
Associate with this SchemaEvent's parent object. |
Method | _validate_dest_table |
Undocumented |
Method | copy |
Undocumented |
Class Variable | __visit_name__ |
Undocumented |
Class Variable | columns |
A _expression.ColumnCollection representing the set of columns for this constraint. |
Instance Variable | elements |
A sequence of _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 | _col_description |
Undocumented |
Property | _elements |
Undocumented |
Property | _referred_schema |
Undocumented |
Property | column_keys |
Return a list of string keys representing the local columns in this _schema.ForeignKeyConstraint . |
Property | referred_table |
The _schema.Table object to which this _schema.ForeignKeyConstraint references. |
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
):
Method | _check_attach |
Undocumented |
Method | _col_expressions |
Undocumented |
Class Variable | _allow_multiple_tables |
Undocumented |
Instance Variable | _cols_wo_table |
Undocumented |
Instance Variable | _column_flag |
Undocumented |
Instance Variable | _pending_colargs |
Undocumented |
Inherited from Constraint
(via ColumnCollectionConstraint
):
Instance Variable | _create_rule |
Undocumented |
Instance Variable | _type_bound |
Undocumented |
Instance Variable | deferrable |
Undocumented |
Instance Variable | info |
Info dictionary associated with the object, allowing user-defined
data to be associated with this .SchemaItem . |
Instance Variable | initially |
Undocumented |
Instance Variable | name |
Undocumented |
Instance Variable | parent |
Undocumented |
Property | table |
Undocumented |
Inherited from DialectKWArgs
(via ColumnCollectionConstraint
, Constraint
):
Class Method | argument_for |
Add a new kind of dialect-specific keyword argument for this class. |
Method | _kw_reg_for_dialect_cls |
Undocumented |
Method | _validate_dialect_kwargs |
Undocumented |
Class Variable | _dialect_kwargs_traverse_internals |
Undocumented |
Class Variable | _kw_registry |
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 .DialectKWArgs.dialect_kwargs . |
Inherited from SchemaItem
(via ColumnCollectionConstraint
, Constraint
):
Method | __repr__ |
Undocumented |
Method | _init_items |
Initialize the list of child items for this SchemaItem. |
Method | _schema_item_copy |
Undocumented |
Class Variable | _use_schema_map |
Undocumented |
Class Variable | create_drop_stringify_dialect |
Undocumented |
Inherited from SchemaEventTarget
(via ColumnCollectionConstraint
, Constraint
, SchemaItem
):
Method | _set_parent_with_dispatch |
Undocumented |
Inherited from Traversible
(via ColumnCollectionConstraint
, Constraint
, SchemaItem
):
Method | get_children |
Return immediate child .visitors.Traversible elements of this .visitors.Traversible . |
Method | __class_getitem__ |
Undocumented |
Parameters | |
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. |
refcolumns | A sequence of foreign column names or Column objects. The columns must all be located within the same Table. |
name | Optional, the in-database name of the key. |
onupdate | Optional string. If set, emit ON UPDATE <value> when issuing DDL for this constraint. Typical values include CASCADE, DELETE and RESTRICT. |
ondelete | Optional string. If set, emit ON DELETE <value> when issuing DDL for this constraint. Typical values include CASCADE, DELETE and RESTRICT. |
deferrable | Optional bool. If set, emit DEFERRABLE or NOT DEFERRABLE when issuing DDL for this constraint. |
initially | Optional string. If set, emit INITIALLY <value> when issuing DDL for this constraint. |
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
Changed in version 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.
See Also |
link_to_name | if True, the string name given in column is the rendered name of the referenced column, not its locally assigned key. |
match | Optional string. If set, emit MATCH <value> when issuing DDL for this constraint. Typical values include SIMPLE, PARTIAL and FULL. |
table | Undocumented |
info | Optional data dictionary which will be populated into the
New in version 1.0.0.
|
**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.
|
Undocumented
A sequence of _schema.ForeignKey
objects.
Each _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 _schema.ForeignKeyConstraint
.
This list is either the original string arguments sent
to the constructor of the _schema.ForeignKeyConstraint
,
or if the constraint has been initialized with _schema.Column
objects, is the string .key of each element.
The _schema.Table
object to which this
_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.