class documentation

A table-level PRIMARY KEY constraint. The :class:`.PrimaryKeyConstraint` object is present automatically on any :class:`_schema.Table` object; it is assigned a set of :class:`_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 :class:`_schema.Table` can also be specified by using a :class:`.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 :class:`.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 :class:`.PrimaryKeyConstraint` declaration, and those columns otherwise marked as ``primary_key=True`` are ignored. This behavior is intended to be backwards compatible with previous behavior. .. versionchanged:: 0.9.2 Using a mixture of columns within a :class:`.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 :class:`.PrimaryKeyConstraint`, but the usual style of using ``primary_key=True`` flags is still desirable, an empty :class:`.PrimaryKeyConstraint` may be specified, which will take on the primary key column collection from the :class:`_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) ) .. versionadded:: 0.9.2 an empty :class:`.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 :class:`_schema.Table` itself; columns marked as ``primary_key=True`` will be gathered into the empty constraint's column collection.

Method __init__ :param \*columns: A sequence of column names or Column objects.
Class Variable __visit_name__ Undocumented
Property columns_autoinc_first Undocumented
Method _reload repopulate this :class:`.PrimaryKeyConstraint` given a set of columns.
Method _replace Undocumented
Method _set_parent Associate with this SchemaEvent's parent object.
Instance Variable _implicit_generated Undocumented
Property _autoincrement_column 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.
Method copy Undocumented
Class Variable columns A :class:`_expression.ColumnCollection` representing the set of columns for this constraint.
Method _copy Undocumented

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: _DDLColumnArgument, name: Optional[str] = None, deferrable: Optional[bool] = None, initially: Optional[str] = None, info: Optional[_InfoType] = None, _implicit_generated: bool = False, **dialect_kw: Any): (source)

:param \*columns: A sequence of column names or Column objects. :param name: Optional, the in-database name of this constraint. :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 \**dialect_kw: other keyword arguments including dialect-specific arguments are propagated to the :class:`.Constraint` superclass.

@property
columns_autoinc_first: List[Column[Any]] = (source)

Undocumented

def _reload(self, columns: Iterable[Column[Any]]): (source)

repopulate this :class:`.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 :class:`.PrimaryKeyConstraint` object on the parent :class:`_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.

def _replace(self, col: Column[Any]): (source)

Undocumented

def _set_parent(self, parent: SchemaEventTarget, **kw: Any): (source)

Associate with this SchemaEvent's parent object.

_implicit_generated = (source)

Undocumented

@util.ro_memoized_property
_autoincrement_column: Optional[Column[int]] = (source)

Undocumented