From: Mike Bayer Date: Mon, 15 Jan 2007 18:31:32 +0000 (+0000) Subject: - trying to redefine a reflected primary key column as non-primary key raises an... X-Git-Tag: rel_0_3_4~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7a8589994c434c07002809a896c1e4a166f0642;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - trying to redefine a reflected primary key column as non-primary key raises an error --- 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