class ForeignKey(DialectKWArgs, SchemaItem):
Defines a dependency between two columns.
ForeignKey is specified as an argument to a _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 _schema.ForeignKeyConstraint
object. This object will be generated automatically when
a ForeignKey is associated with a _schema.Column
which
in turn is associated with a _schema.Table
. Conversely,
when _schema.ForeignKeyConstraint
is applied to a
_schema.Table
,
ForeignKey markers are automatically generated to be
present on each associated _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 _schema.ForeignKeyConstraint
object must be used, and applied
to the _schema.Table
. The associated ForeignKey objects
are created automatically.
The ForeignKey objects associated with an individual
_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 |
Produce a copy of this _schema.ForeignKey object. |
Method | _get_colspec |
Return a string based 'column specification' for this _schema.ForeignKey . |
Method | _link_to_col_by_colstring |
Undocumented |
Method | _remove_from_metadata |
Undocumented |
Method | _resolve_col_tokens |
Undocumented |
Method | _set_parent |
Associate with this SchemaEvent's parent object. |
Method | _set_remote_table |
Undocumented |
Method | _set_table |
Undocumented |
Method | _set_target_column |
Undocumented |
Method | _table_key |
Undocumented |
Method | copy |
Undocumented |
Method | get_referent |
Return the _schema.Column in the given _schema.Table referenced by this _schema.ForeignKey . |
Method | references |
Return True if the given _schema.Table is referenced by this _schema.ForeignKey . |
Class Variable | __visit_name__ |
Undocumented |
Class Variable | target_fullname |
Undocumented |
Instance Variable | _colspec |
Undocumented |
Instance Variable | _table_column |
Undocumented |
Instance Variable | _unvalidated_dialect_kw |
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 .SchemaItem . |
Instance Variable | initially |
Undocumented |
Instance Variable | link_to_name |
Undocumented |
Instance Variable | match |
Undocumented |
Instance Variable | name |
Undocumented |
Instance Variable | ondelete |
Undocumented |
Instance Variable | onupdate |
Undocumented |
Instance Variable | parent |
Undocumented |
Instance Variable | use_alter |
Undocumented |
Property | _column_tokens |
parse a string-based _colspec into its component parts. |
Property | _referred_schema |
Undocumented |
Property | column |
Return the target _schema.Column referenced by this _schema.ForeignKey . |
Inherited from DialectKWArgs
:
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
:
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 SchemaItem
):
Method | _set_parent_with_dispatch |
Undocumented |
Inherited from Traversible
(via SchemaItem
):
Method | get_children |
Return immediate child .visitors.Traversible elements of this .visitors.Traversible . |
Method | __class_getitem__ |
Undocumented |
Construct a column-level FOREIGN KEY.
The _schema.ForeignKey
object when constructed generates a
_schema.ForeignKeyConstraint
which is associated with the parent
_schema.Table
object's collection of constraints.
Parameters | |
column | A single target column for the key relationship. A
_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. |
_constraint | Undocumented |
use_alter | passed to the underlying
|
name | Optional string. An in-database name for the key if
constraint is not provided. |
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. |
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. |
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>. The
arguments are ultimately handled by a corresponding
New in version 0.9.2.
|
Produce a copy of this _schema.ForeignKey
object.
The new _schema.ForeignKey
will not be bound
to any _schema.Column
.
This method is usually used by the internal
copy procedures of _schema.Column
, _schema.Table
,
and _schema.MetaData
.
Parameters | |
schema | The returned _schema.ForeignKey will
reference the original table and column name, qualified
by the given string schema name. |
**kw | Undocumented |
Return a string based 'column specification' for this
_schema.ForeignKey
.
This is usually the equivalent of the string-based "tablename.colname" argument first passed to the object's constructor.
Undocumented
Return the _schema.Column
in the given
_schema.Table
referenced by this _schema.ForeignKey
.
Returns None if this _schema.ForeignKey
does not reference the given
_schema.Table
.
_schema.Table
is referenced by this
_schema.ForeignKey
.sqlalchemy.sql.schema.SchemaItem.info
Info dictionary associated with the object, allowing user-defined
data to be associated with this .SchemaItem
.
The dictionary is automatically generated when first accessed.
It can also be specified in the constructor of some objects,
such as _schema.Table
and _schema.Column
.
Return the target _schema.Column
referenced by this
_schema.ForeignKey
.
If no target column has been established, an exception is raised.