]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- trying to redefine a reflected primary key column as non-primary key raises an...
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 15 Jan 2007 18:31:32 +0000 (18:31 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 15 Jan 2007 18:31:32 +0000 (18:31 +0000)
CHANGES
lib/sqlalchemy/schema.py

diff --git a/CHANGES b/CHANGES
index 9021cb2817cc9065c9d6c8c32aa73733d7d6e956..892d28e26ab643ce7416c1566af92ca2cc906ef3 100644 (file)
--- 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:
index e8b2d06e0c7fca4276340b2e0b8423de02dce60f..8b36ba0264859b0e93166d7f83f395f6dfef97d4 100644 (file)
@@ -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