From bf03d4332ae35e2087b175f8a2e0291d2f4c9aa0 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 20 Jun 2016 11:39:01 -0400 Subject: Don't reorder PrimaryKeyConstraint columns if explicit Dialed back the "order the primary key columns per auto-increment" described in :ref:`change_mysql_3216` a bit, so that if the :class:`.PrimaryKeyConstraint` is explicitly defined, the order of columns is maintained exactly, allowing control of this behavior when necessary. Change-Id: I9e7902c57a96c15968a6abf53e319acf15680da0 Fixes: #3726 --- lib/sqlalchemy/sql/schema.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/sql/schema.py') diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index cb01a49e3..ee139827a 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -475,7 +475,8 @@ class Table(DialectKWArgs, SchemaItem, TableClause): self.indexes = set() self.constraints = set() self._columns = ColumnCollection() - PrimaryKeyConstraint()._set_parent_with_dispatch(self) + PrimaryKeyConstraint(_implicit_generated=True).\ + _set_parent_with_dispatch(self) self.foreign_keys = set() self._extra_dependencies = set() if self.schema is not None: @@ -3023,6 +3024,10 @@ class PrimaryKeyConstraint(ColumnCollectionConstraint): __visit_name__ = 'primary_key_constraint' + def __init__(self, *columns, **kw): + self._implicit_generated = kw.pop('_implicit_generated', False) + super(PrimaryKeyConstraint, self).__init__(*columns, **kw) + def _set_parent(self, table): super(PrimaryKeyConstraint, self)._set_parent(table) -- cgit v1.2.1