summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/databases/mysql.py
diff options
context:
space:
mode:
authorJason Kirtland <jek@discorporate.us>2008-10-27 22:56:53 +0000
committerJason Kirtland <jek@discorporate.us>2008-10-27 22:56:53 +0000
commitc9591657dd2c4f92f86590adc9af622f48c0e064 (patch)
treea3ea946b2533124720e6bb0b6b6b05a05d86d642 /lib/sqlalchemy/databases/mysql.py
parentd56c1f1663629fe9df1f658f6a82ce8d278a3745 (diff)
downloadsqlalchemy-c9591657dd2c4f92f86590adc9af622f48c0e064.tar.gz
Fixed mysql FK reflection for the edge case where a Table has expicitly provided a schema= that matches the connection's default schema.
Diffstat (limited to 'lib/sqlalchemy/databases/mysql.py')
-rw-r--r--lib/sqlalchemy/databases/mysql.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py
index f1187b8ac..743ec96ea 100644
--- a/lib/sqlalchemy/databases/mysql.py
+++ b/lib/sqlalchemy/databases/mysql.py
@@ -2334,11 +2334,20 @@ class MySQLSchemaReflector(object):
def _set_constraints(self, table, constraints, connection, only):
"""Apply constraints to a ``Table``."""
+ default_schema = None
+
for spec in constraints:
# only FOREIGN KEYs
ref_name = spec['table'][-1]
ref_schema = len(spec['table']) > 1 and spec['table'][-2] or None
+ if not ref_schema:
+ if default_schema is None:
+ default_schema = connection.dialect.get_default_schema_name(
+ connection)
+ if table.schema == default_schema:
+ ref_schema = table.schema
+
loc_names = spec['local']
if only and not set(loc_names).issubset(only):
self.logger.info(