summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/schema.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-02-04 12:09:54 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2021-02-04 12:11:41 -0500
commit9660e94e35be438b0d51cd87e6ccb4047a332c15 (patch)
tree0a888b4fb18430618bca045b3c2456dff893f6cb /lib/sqlalchemy/sql/schema.py
parente91d918fc24d678a413feb3744e70014f54172c7 (diff)
downloadsqlalchemy-9660e94e35be438b0d51cd87e6ccb4047a332c15.tar.gz
Accommodate column-based naming conventions for pk constraint
Repaired / implemented support for primary key constraint naming conventions that use column names/keys/etc as part of the convention. In particular, this includes that the :class:`.PrimaryKeyConstraint` object that's automatically associated with a :class:`.schema.Table` will update its name as new primary key :class:`_schema.Column` objects are added to the table and then to the constraint. Internal failure modes related to this constraint construction process including no columns present, no name present or blank name present are now accommodated. Fixes: #5919 Change-Id: Ic2800b50f4a4cd5978bec48cefea0a2e198e0123
Diffstat (limited to 'lib/sqlalchemy/sql/schema.py')
-rw-r--r--lib/sqlalchemy/sql/schema.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py
index 34bedbc6a..127b12e81 100644
--- a/lib/sqlalchemy/sql/schema.py
+++ b/lib/sqlalchemy/sql/schema.py
@@ -1777,6 +1777,8 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause):
table._columns.replace(self)
+ self.table = table
+
if self.primary_key:
table.primary_key._replace(self)
elif self.key in table.primary_key:
@@ -1786,8 +1788,6 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause):
% (self.key, table.fullname)
)
- self.table = table
-
if self.index:
if isinstance(self.index, util.string_types):
raise exc.ArgumentError(
@@ -3838,7 +3838,6 @@ class PrimaryKeyConstraint(ColumnCollectionConstraint):
are already present.
"""
-
# set the primary key flag on new columns.
# note any existing PK cols on the table also have their
# flag still set.
@@ -3854,6 +3853,8 @@ class PrimaryKeyConstraint(ColumnCollectionConstraint):
PrimaryKeyConstraint._autoincrement_column._reset(self)
self.columns.replace(col)
+ self.dispatch._sa_event_column_added_to_pk_constraint(self, col)
+
@property
def columns_autoinc_first(self):
autoinc = self._autoincrement_column