From f7a8589994c434c07002809a896c1e4a166f0642 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 15 Jan 2007 18:31:32 +0000 Subject: [PATCH] - trying to redefine a reflected primary key column as non-primary key raises an error --- CHANGES | 1 + lib/sqlalchemy/schema.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGES b/CHANGES index 9021cb2817..892d28e26a 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,7 @@ - the "op()" function is now treated as an "operation", rather than a "comparison". the difference is, an operation produces a BinaryExpression from which further operations can occur whereas comparison produces the more restrictive BooleanExpression + - trying to redefine a reflected primary key column as non-primary key raises an error - type system slightly modified to support TypeDecorators that can be overridden by the dialect (ok, thats not very clear, it allows the mssql tweak below to be possible) - mssql: diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index e8b2d06e0c..8b36ba0264 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -438,6 +438,10 @@ class Column(SchemaItem, sql._ColumnClause): table._columns.add(self) if self.primary_key: table.primary_key.add(self) + elif self.key in table.primary_key: + raise exceptions.ArgumentError("Trying to redefine primary-key column '%s' as a non-primary-key column on table '%s'" % (self.key, table.fullname)) + # if we think this should not raise an error, we'd instead do this: + #table.primary_key.remove(self) self.table = table if self.index: @@ -752,6 +756,9 @@ class PrimaryKeyConstraint(Constraint): visitor.visit_primary_key_constraint(self) def add(self, col): self.append_column(col) + def remove(self, col): + col.primary_key=False + del self.columns[col.key] def append_column(self, col): self.columns.add(col) col.primary_key=True -- 2.47.2