Nuqlear · GitHub

Describe the bug

op.drop_column("assignment", "employee_profile_id", mssql_drop_foreign_key=True)

This line is generating the following statement:

declare @const_name varchar(256)
select @const_name = [name] from
sys.foreign_keys fk join sys.foreign_key_columns fkc
on fk.object_id=fkc.constraint_object_id
where fkc.parent_object_id = object_id('assignment')
`and col_name(fkc.parent_object_id, fkc.parent_column_id) = 'employee_profile_id'
exec('alter table assignment drop constraint ' + @const_name)

which leads to pyodbc.ProgrammingError:

pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near '`'. (102) (SQLExecDirectW)")

Expected behavior
Foreign key dropped alongside column without errors.

Versions.

  • OS: Ubuntu 18.04
  • Python: 3.7.4
  • Alembic: 1.4.2
  • SQLAlchemy: 1.3.14
  • Database: Azure SQL Server
  • DBAPI: pyodbc==4.0.30

Read the original on github.com ↗