From c9591657dd2c4f92f86590adc9af622f48c0e064 Mon Sep 17 00:00:00 2001 From: Jason Kirtland Date: Mon, 27 Oct 2008 22:56:53 +0000 Subject: Fixed mysql FK reflection for the edge case where a Table has expicitly provided a schema= that matches the connection's default schema. --- lib/sqlalchemy/databases/mysql.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib/sqlalchemy/databases/mysql.py') 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( -- cgit v1.2.1