From 84a78a97b5903dc246155a63ee8514385ed95d7c Mon Sep 17 00:00:00 2001 From: Gord Thompson Date: Mon, 14 Mar 2022 11:26:54 -0600 Subject: [PATCH] Fix "Ambiguous column name" error on FK reflection Fixes: #7812 Change-Id: Ic16eff9a9201d34515cb8eb884270eced4e1196a --- doc/build/changelog/unreleased_14/7812.rst | 7 +++++++ lib/sqlalchemy/dialects/mssql/base.py | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 doc/build/changelog/unreleased_14/7812.rst diff --git a/doc/build/changelog/unreleased_14/7812.rst b/doc/build/changelog/unreleased_14/7812.rst new file mode 100644 index 0000000000..7e28428acf --- /dev/null +++ b/doc/build/changelog/unreleased_14/7812.rst @@ -0,0 +1,7 @@ +.. change:: + :tags: bug, mssql, regression + :tickets: 7812 + + Fixed regression caused by :ticket:`7160` where FK reflection on a very + old database (compatibility level 80: SQL Server 2000) causes an + "Ambiguous column name" error. Patch courtesy of @Lin-Your. diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index 8c44c0b2d2..dd792f70d7 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -3422,7 +3422,8 @@ index_info AS ( AND index_info.index_name = fk_info.unique_constraint_name AND index_info.ordinal_position = fk_info.ordinal_position - ORDER BY constraint_schema, constraint_name, ordinal_position + ORDER BY fk_info.constraint_schema, fk_info.constraint_name, + fk_info.ordinal_position """ ) .bindparams( -- 2.47.2