diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-12-26 05:28:38 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-12-26 05:28:38 +0000 |
commit | 83a756c5415fad752933ed7f1aff69d2a184d618 (patch) | |
tree | 679b6d9ef7f383fc1c82fa4f27cc7591f015c116 /lib/sqlalchemy/databases/postgres.py | |
parent | 3ea2888b7f84ef7571c847991149c7372dd3db49 (diff) | |
download | sqlalchemy-83a756c5415fad752933ed7f1aff69d2a184d618.tar.gz |
- Reflected foreign keys will properly locate
their referenced column, even if the column
was given a "key" attribute different from
the reflected name. This is achieved via a
new flag on ForeignKey/ForeignKeyConstraint
called "link_to_name", if True means the given
name is the referred-to column's name, not its
assigned key.
[ticket:650]
- removed column types from sqlite doc, we
aren't going to list out "implementation" types
since they aren't significant and are less present
in 0.6
- mysql will report on missing reflected foreign
key targets in the same way as other dialects
(we can improve that to be immediate within
reflecttable(), but it should be within
ForeignKeyConstraint()).
- postgres dialect can reflect table with
an include_columns list that doesn't include
one or more primary key columns
Diffstat (limited to 'lib/sqlalchemy/databases/postgres.py')
-rw-r--r-- | lib/sqlalchemy/databases/postgres.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index 0a6c12f9b..273f5859e 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -577,10 +577,11 @@ class PGDialect(default.DefaultDialect): c = connection.execute(t, table=table_oid) for row in c.fetchall(): pk = row[0] - col = table.c[pk] - table.primary_key.add(col) - if col.default is None: - col.autoincrement = False + if pk in table.c: + col = table.c[pk] + table.primary_key.add(col) + if col.default is None: + col.autoincrement = False # Foreign keys FK_SQL = """ @@ -617,7 +618,7 @@ class PGDialect(default.DefaultDialect): for column in referred_columns: refspec.append(".".join([referred_table, column])) - table.append_constraint(schema.ForeignKeyConstraint(constrained_columns, refspec, conname)) + table.append_constraint(schema.ForeignKeyConstraint(constrained_columns, refspec, conname, link_to_name=True)) # Indexes IDX_SQL = """ |