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/mysql.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/mysql.py')
-rw-r--r-- | lib/sqlalchemy/databases/mysql.py | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py index e22f242ea..86fb7b247 100644 --- a/lib/sqlalchemy/databases/mysql.py +++ b/lib/sqlalchemy/databases/mysql.py @@ -2326,23 +2326,19 @@ class MySQLSchemaReflector(object): autoload=True, autoload_with=connection) ref_names = spec['foreign'] - if not set(ref_names).issubset( - set(c.name for c in ref_table.c)): - raise exc.InvalidRequestError( - "Foreign key columns (%s) are not present on " - "foreign table %s" % - (', '.join(ref_names), ref_table.fullname)) - ref_columns = [ref_table.c[name] for name in ref_names] + + if ref_schema: + refspec = [".".join([ref_schema, ref_name, column]) for column in ref_names] + else: + refspec = [".".join([ref_name, column]) for column in ref_names] con_kw = {} for opt in ('name', 'onupdate', 'ondelete'): if spec.get(opt, False): con_kw[opt] = spec[opt] - key = schema.ForeignKeyConstraint([], [], **con_kw) + key = schema.ForeignKeyConstraint(loc_names, refspec, link_to_name=True, **con_kw) table.append_constraint(key) - for pair in zip(loc_names, ref_columns): - key.append_element(*pair) def _set_options(self, table, line): """Apply safe reflected table options to a ``Table``. |