Users(password, api_user=None, **kwargs)¶
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
api_user= Column(None, String(length=32), table=None)¶
api_version= Column(None, String(length=8), table=None, default=ColumnDefault('1.0.0'))¶
datetime_created= Column(None, DateTime(), table=None, nullable=False)¶
DescribedColumn(col_type, description='', *args, **kwargs)¶
Construct a new
The name of this column as represented in the database. This argument may be the first positional argument, or specified via keyword.
Names which contain no upper case characters will be treated as case insensitive names, and will not be quoted unless they are a reserved word. Names with any number of upper case characters will be quoted and sent exactly. Note that this behavior applies even for databases which standardize upper case names as case insensitive such as Oracle.
The name field may be omitted at construction time and applied later, at any time before the Column is associated with a
_schema.Table. This is to support convenient usage within the
The column’s type, indicated using an instance which subclasses
TypeEngine. If no arguments are required for the type, the class of the type can be sent as well, e.g.:
# use a type with arguments Column('data', String(50)) # use no arguments Column('level', Integer)
typeargument may be the second positional argument or specified by keyword.
Noneor is omitted, it will first default to the special type
NullType. If and when this
_schema.Columnis made to refer to another column using
_schema.ForeignKeyConstraint, the type of the remote-referenced column will be copied to this column as well, at the moment that the foreign key is resolved against that remote
Changed in version 0.9.0: Support for propagation of type to a
_schema.ForeignKeyobject has been improved and should be more reliable and timely.
*args – Additional positional arguments include various
SchemaItemderived constructs which will be applied as options to the column. These include instances of
Computed. In some cases an equivalent keyword argument is available such as
Set up “auto increment” semantics for an integer primary key column. The default value is the string
"auto"which indicates that a single-column primary key that is of an INTEGER type with no stated client-side or python-side defaults should receive auto increment semantics automatically; all other varieties of primary key columns will not. This includes that DDL such as PostgreSQL SERIAL or MySQL AUTO_INCREMENT will be emitted for this column during a table create, as well as that the column is assumed to generate new integer primary key values when an INSERT statement invokes which will be retrieved by the dialect.
The flag may be set to
Trueto indicate that a column which is part of a composite (e.g. multi-column) primary key should have autoincrement semantics, though note that only one column within a primary key may have this setting. It can also be set to
Trueto indicate autoincrement semantics on a column that has a client-side or server-side default configured, however note that not all dialects can accommodate all styles of default as an “autoincrement”. It can also be set to
Falseon a single-column primary key that has a datatype of INTEGER in order to disable auto increment semantics for that column.
Changed in version 1.1: The autoincrement flag now defaults to
"auto"which indicates autoincrement semantics by default for single-column integer primary keys only; for composite (multi-column) primary keys, autoincrement is never implicitly enabled; as always,
autoincrement=Truewill allow for at most one of those columns to be an “autoincrement” column.
autoincrement=Truemay also be set on a
_schema.Columnthat has an explicit client-side or server-side default, subject to limitations of the backend database and dialect.
The setting only has an effect for columns which are:
Integer derived (i.e. INT, SMALLINT, BIGINT).
Part of the primary key
Not referring to another column via
_schema.ForeignKey, unless the value is specified as
# turn on autoincrement for this column despite # the ForeignKey() Column('id', ForeignKey('other.id'), primary_key=True, autoincrement='ignore_fk')
It is typically not desirable to have “autoincrement” enabled on a column that refers to another via foreign key, as such a column is required to refer to a value that originates from elsewhere.
The setting has these two effects on columns that meet the above criteria:
DDL issued for the column will include database-specific keywords intended to signify this column as an “autoincrement” column, such as AUTO INCREMENT on MySQL, SERIAL on PostgreSQL, and IDENTITY on MS-SQL. It does not issue AUTOINCREMENT for SQLite since this is a special SQLite flag that is not required for autoincrementing behavior.
The column will be considered to be available using an “autoincrement” method specific to the backend database, such as calling upon
cursor.lastrowid, using RETURNING in an INSERT statement to get at a sequence-generated value, or using special functions such as “SELECT scope_identity()”. These methods are highly specific to the DBAPIs and databases in use and vary greatly, so care should be taken when associating
autoincrement=Truewith a custom default generation function.
A scalar, Python callable, or
_expression.ColumnElementexpression representing the default value for this column, which will be invoked upon insert if this column is otherwise not specified in the VALUES clause of the insert. This is a shortcut to using
ColumnDefaultas a positional argument; see that class for full detail on the structure of the argument.
Contrast this argument to :paramref:`_schema.Column.server_default` which creates a default generator on the database side.
doc – optional String that can be used by the ORM or similar to document attributes on the Python side. This attribute does not render SQL comments; use the :paramref:`_schema.Column.comment` parameter for this purpose.
key – An optional string identifier which will identify this
Columnobject on the
_schema.Table. When a key is provided, this is the only identifier referencing the
Columnwithin the application, including ORM attribute mapping; the
namefield is used only when rendering SQL.
True, indicates that a
_schema.Indexconstruct will be automatically generated for this
_schema.Column, which will result in a “CREATE INDEX” statement being emitted for the
_schema.Tablewhen the DDL create operation is invoked.
Using this flag is equivalent to making use of the
_schema.Indexconstruct explicitly at the level of the
Table( "some_table", metadata, Column("x", Integer), Index("ix_some_table_x", "x") )
To add the :paramref:`_schema.Index.unique` flag to the
_schema.Index, set both the :paramref:`_schema.Column.unique` and :paramref:`_schema.Column.index` flags to True simultaneously, which will have the effect of rendering the “CREATE UNIQUE INDEX” DDL instruction instead of “CREATE INDEX”.
The name of the index is generated using the default naming convention which for the
_schema.Indexconstruct is of the form
As this flag is intended only as a convenience for the common case of adding a single-column, default configured index to a table definition, explicit use of the
_schema.Indexconstruct should be preferred for most use cases, including composite indexes that encompass more than one column, indexes with SQL expressions or ordering, backend-specific index configuration options, and indexes that use a specific name.
_schema.Columndoes not indicate if this column is indexed or not, only if this flag was explicitly set here. To view indexes on a column, view the
_schema.Table.indexescollection or use
info – Optional data dictionary which will be populated into the
SchemaItem.infoattribute of this object.
nullable – When set to
False, will cause the “NOT NULL” phrase to be added when generating DDL for the column. When
True, will normally generate nothing (in SQL this defaults to “NULL”), except in some very specific backend-specific edge cases where “NULL” may render explicitly. Defaults to
Trueunless :paramref:`_schema.Column.primary_key` is also
True, in which case it defaults to
False. This parameter is only used when issuing CREATE TABLE statements.
A scalar, Python callable, or
ClauseElementrepresenting a default value to be applied to the column within UPDATE statements, which will be invoked upon update if this column is not present in the SET clause of the update. This is a shortcut to using
ColumnDefaultas a positional argument with
Column INSERT/UPDATE Defaults - complete discussion of onupdate
primary_key – If
True, marks this column as a primary key column. Multiple columns can have this flag set to specify composite primary keys. As an alternative, the primary key of a
_schema.Tablecan be specified via an explicit
FetchedValueinstance, str, Unicode or
text()construct representing the DDL DEFAULT value for the column.
String types will be emitted as-is, surrounded by single quotes:
Column('x', Text, server_default="val") x TEXT DEFAULT 'val'
text()expression will be rendered as-is, without quotes:
Column('y', DateTime, server_default=text('NOW()')) y DATETIME DEFAULT NOW()
Strings and text() will be converted into a
DefaultClauseobject upon initialization.
FetchedValueto indicate that an already-existing column will generate a default value on the database side which will be available to SQLAlchemy for post-fetch after inserts. This construct does not specify any DDL and the implementation is left to the database, such as via a trigger.
Server-invoked DDL-Explicit Default Expressions - complete discussion of server side defaults
FetchedValueinstance representing a database-side default generation function, such as a trigger. This indicates to SQLAlchemy that a newly generated value will be available after updates. This construct does not actually implement any kind of generation function within the database, which instead must be specified separately.
This directive does not currently produce MySQL’s “ON UPDATE CURRENT_TIMESTAMP()” clause. See Rendering ON UPDATE CURRENT TIMESTAMP for MySQL’s explicit_defaults_for_timestamp for background on how to produce this clause.
quote – Force quoting of this column’s name on or off, corresponding to
False. When left at its default of
None, the column identifier will be quoted according to whether the name is case sensitive (identifiers with at least one upper case character are treated as case sensitive), or if it’s a reserved word. This flag is only needed to force quoting of a reserved word which is not known by the SQLAlchemy dialect.
True, and the :paramref:`_schema.Column.index` parameter is left at its default value of
False, indicates that a
_schema.UniqueConstraintconstruct will be automatically generated for this
_schema.Column, which will result in a “UNIQUE CONSTRAINT” clause referring to this column being included in the
CREATE TABLEstatement emitted, when the DDL create operation for the
_schema.Tableobject is invoked.
When this flag is
Truewhile the :paramref:`_schema.Column.index` parameter is simultaneously set to
True, the effect instead is that a
_schema.Indexconstruct which includes the :paramref:`_schema.Index.unique` parameter set to
Trueis generated. See the documentation for :paramref:`_schema.Column.index` for additional detail.
Using this flag is equivalent to making use of the
_schema.UniqueConstraintconstruct explicitly at the level of the
Table( "some_table", metadata, Column("x", Integer), UniqueConstraint("x") )
The :paramref:`_schema.UniqueConstraint.name` parameter of the unique constraint object is left at its default value of
None; in the absence of a naming convention for the enclosing
_schema.MetaData, the UNIQUE CONSTRAINT construct will be emitted as unnamed, which typically invokes a database-specific naming convention to take place.
As this flag is intended only as a convenience for the common case of adding a single-column, default configured unique constraint to a table definition, explicit use of the
_schema.UniqueConstraintconstruct should be preferred for most use cases, including composite constraints that encompass more than one column, backend-specific index configuration options, and constraints that use a specific name.
_schema.Columndoes not indicate if this column has a unique constraint or not, only if this flag was explicitly set here. To view indexes and unique constraints that may involve this column, view the
_schema.Table.constraintscollections or use
True, indicates this is a “system” column, that is a column which is automatically made available by the database, and should not be included in the columns list for a
For more elaborate scenarios where columns should be conditionally rendered differently on different backends, consider custom compilation rules for
Optional string that will render an SQL comment on table creation.
New in version 1.2: Added the :paramref:`_schema.Column.comment` parameter to