Permalink
Browse files

Fixed error with foreign keys against unique or primary key columns

  • Loading branch information...
1 parent 0ee086b commit 86f53f6751e4148f3d1697e28fabc7fd41ef4925 mitch committed Apr 9, 2011
Showing with 7 additions and 2 deletions.
  1. +1 −0 CHANGES
  2. +6 −2 schemaobject/foreignkey.py
View
@@ -1,5 +1,6 @@
== 0.5.4
* Sub-parts of indices are now correctly added
+ * Fixes error with foreign keys against unique or primary key columns
== 0.5.3 / 2010-04-19
* Column types are no longer forced uppercase
@@ -31,6 +31,7 @@ def ForeignKeySchemaBuilder(table):
AND T.CONSTRAINT_TYPE = 'FOREIGN KEY'
AND K.CONSTRAINT_SCHEMA='%s'
AND K.TABLE_NAME='%s'
+ AND K.REFERENCED_TABLE_NAME is not null
"""
constraints = conn.execute(sql % (table.parent.name, table.name))
@@ -59,13 +60,16 @@ def ForeignKeySchemaBuilder(table):
fkeys[n] = FKItem
+ # POSITION_IN_UNIQUE_CONSTRAINT may be None
+ pos = fk['POSITION_IN_UNIQUE_CONSTRAINT'] or 0
+
#columns for this fk
if fk['COLUMN_NAME'] not in fkeys[n].columns:
- fkeys[n].columns.insert(fk['POSITION_IN_UNIQUE_CONSTRAINT'], fk['COLUMN_NAME'])
+ fkeys[n].columns.insert(pos, fk['COLUMN_NAME'])
#referenced columns for this fk
if fk['REFERENCED_COLUMN_NAME'] not in fkeys[n].referenced_columns:
- fkeys[n].referenced_columns.insert(fk['POSITION_IN_UNIQUE_CONSTRAINT'], fk['REFERENCED_COLUMN_NAME'])
+ fkeys[n].referenced_columns.insert(pos, fk['REFERENCED_COLUMN_NAME'])
return fkeys

0 comments on commit 86f53f6

Please sign in to comment.