summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine/reflection.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/engine/reflection.py')
-rw-r--r--lib/sqlalchemy/engine/reflection.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py
index f5911f3b6..71d97e65f 100644
--- a/lib/sqlalchemy/engine/reflection.py
+++ b/lib/sqlalchemy/engine/reflection.py
@@ -317,7 +317,7 @@ class Inspector(object):
info_cache=self.info_cache, **kw)
return indexes
- def reflecttable(self, table, include_columns, exclude_columns=None):
+ def reflecttable(self, table, include_columns, exclude_columns=()):
"""Given a Table object, load its internal constructs based on introspection.
This is the underlying method used by most dialects to produce
@@ -414,9 +414,12 @@ class Inspector(object):
# Primary keys
pk_cons = self.get_pk_constraint(table_name, schema, **tblkw)
if pk_cons:
+ pk_cols = [table.c[pk]
+ for pk in pk_cons['constrained_columns']
+ if pk in table.c and pk not in exclude_columns
+ ] + [pk for pk in table.primary_key if pk.key in exclude_columns]
primary_key_constraint = sa_schema.PrimaryKeyConstraint(name=pk_cons.get('name'),
- *[table.c[pk] for pk in pk_cons['constrained_columns']
- if pk in table.c]
+ *pk_cols
)
table.append_constraint(primary_key_constraint)