Skip to content

Problem in MSSQL altering column when change type and server_default in one statement #1744

@fbuccioni

Description

@fbuccioni

Describe the bug

Hi
I'm Trying to change type and server default value of a column, but it complains about it have a dependent object with an error, the idea is to have the same mssql_drop_* parameters in alter table also

Expected behavior
To be able to drop the constraints asociated with the column

To Reproduce

    op.alter_column('access', 'created_at',
               existing_type=sa.DATETIME(),
               type_=sqlalchemy_utc.sqltypes.UtcDateTime(timezone=True),
               server_default=sqlalchemy_utc.utcnow(),  # type: ignore
               existing_nullable=False,
               existing_server_default=sa.text('(getutcdate())'))

Error

    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (pyodbc.ProgrammingError) ('42000', "[42000] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]The object 'DF__access__created___2B0A656D' is dependent on column 'created_at'. (5074) (SQLExecDirectW)")
[SQL: ALTER TABLE access ALTER COLUMN created_at DATETIMEOFFSET NOT NULL]
(Background on this error at: https://sqlalche.me/e/20/f405)

Versions.

  • OS: Linux KDE Neon / Ubuntu Noble 2024.4
  • Python: Python 3.12.3 (main, Aug 14 2025, 17:47:21) [GCC 13.3.0] on linux
  • Alembic: alembic 1.17.0
  • SQLAlchemy: 2.0.37
  • Database: Microsoft SQL Server 2025 preview
  • DBAPI: mssql (UnixODBC)

Have a awesome day! thanks for your amazing job with alembic

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions