class PrimaryKeyConstraint(ColumnCollectionConstraint):
A table-level PRIMARY KEY constraint.
The .PrimaryKeyConstraint
object is present automatically
on any _schema.Table
object; it is assigned a set of
_schema.Column
objects corresponding to those marked with
the :paramref:`_schema.Column.primary_key` flag:
>>> my_table = Table('mytable', metadata, ... Column('id', Integer, primary_key=True), ... Column('version_id', Integer, primary_key=True), ... Column('data', String(50)) ... ) >>> my_table.primary_key PrimaryKeyConstraint( Column('id', Integer(), table=<mytable>, primary_key=True, nullable=False), Column('version_id', Integer(), table=<mytable>, primary_key=True, nullable=False) )
The primary key of a _schema.Table
can also be specified by using
a .PrimaryKeyConstraint
object explicitly; in this mode of usage,
the "name" of the constraint can also be specified, as well as other
options which may be recognized by dialects:
my_table = Table('mytable', metadata, Column('id', Integer), Column('version_id', Integer), Column('data', String(50)), PrimaryKeyConstraint('id', 'version_id', name='mytable_pk') )
The two styles of column-specification should generally not be mixed.
An warning is emitted if the columns present in the
.PrimaryKeyConstraint
don't match the columns that were marked as primary_key=True, if both
are present; in this case, the columns are taken strictly from the
.PrimaryKeyConstraint
declaration, and those columns otherwise
marked as primary_key=True are ignored. This behavior is intended to
be backwards compatible with previous behavior.
.PrimaryKeyConstraint
in addition to columns marked as
primary_key=True now emits a warning if the lists don't match.
The ultimate behavior of ignoring those columns marked with the flag
only is currently maintained for backwards compatibility; this warning
may raise an exception in a future release.For the use case where specific options are to be specified on the
.PrimaryKeyConstraint
, but the usual style of using
primary_key=True flags is still desirable, an empty
.PrimaryKeyConstraint
may be specified, which will take on the
primary key column collection from the _schema.Table
based on the
flags:
my_table = Table('mytable', metadata, Column('id', Integer, primary_key=True), Column('version_id', Integer, primary_key=True), Column('data', String(50)), PrimaryKeyConstraint(name='mytable_pk', mssql_clustered=True) )
.PrimaryKeyConstraint
may now
be specified for the purposes of establishing keyword arguments with
the constraint, independently of the specification of "primary key"
columns within the _schema.Table
itself; columns marked as
primary_key=True will be gathered into the empty constraint's
column collection.Method | __init__ |
|
Method | _reload |
repopulate this .PrimaryKeyConstraint given a set of columns. |
Method | _replace |
Undocumented |
Method | _set_parent |
Associate with this SchemaEvent's parent object. |
Class Variable | __visit_name__ |
Undocumented |
Instance Variable | _implicit_generated |
Undocumented |
Property | _autoincrement_column |
Undocumented |
Property | columns_autoinc_first |
Undocumented |
Inherited from ColumnCollectionConstraint
:
Method | __contains__ |
Undocumented |
Method | __iter__ |
Undocumented |
Method | __len__ |
Undocumented |
Method | _copy |
Undocumented |
Method | contains_column |
Return True if this constraint contains the given column. |
Method | copy |
Undocumented |
Class Variable | columns |
A _expression.ColumnCollection representing the set of columns for this constraint. |
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 column names or Column objects. |
**kw | other keyword arguments including dialect-specific
arguments are propagated to the .Constraint superclass. |
name | Optional, the in-database name of this constraint. |
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. |
repopulate this .PrimaryKeyConstraint
given
a set of columns.
Existing columns in the table that are marked as primary_key=True are maintained.
Also fires a new event.
This is basically like putting a whole new
.PrimaryKeyConstraint
object on the parent
_schema.Table
object without actually replacing the object.
The ordering of the given list of columns is also maintained; these columns will be appended to the list of columns after any which are already present.