Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop_column(mssql_drop_check=True) doesn't quote names properly when generating 'drop constraint' SQL #186

sqlalchemy-bot opened this issue Mar 12, 2014 · 2 comments


Copy link

@sqlalchemy-bot sqlalchemy-bot commented Mar 12, 2014

Migrated issue, originally created by Marek Baczyński (@imbaczek)

DB: SQL Server 2008R2



def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('table', sa.Column('col3', sa.Boolean(name='ck_col3'), nullable=True))
    ### end Alembic commands ###

def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('table', 'col3', mssql_drop_check=True)
    ### end Alembic commands ###

when downgrading, alembic emits the following SQL

declare @const_name varchar(256)
select @const_name = [name] from sys.check_constraints
where parent_object_id = object_id('table')
and col_name(parent_object_id, parent_column_id) = 'col3'
-- expected
exec('alter table [table] drop constraint [' + @const_name + ']')
-- actually emitted
exec('alter table table drop constraint ' + @const_name)
Copy link

@sqlalchemy-bot sqlalchemy-bot commented Mar 25, 2014

Michael Bayer (@zzzeek) wrote:

  • Added quoting to the table name when the special EXEC is run to
    drop any existing server defaults or constraints when the
    :paramref:.drop_column.mssql_drop_check or
    arguments are used. fix #186


Copy link

@sqlalchemy-bot sqlalchemy-bot commented Mar 25, 2014

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant